home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume9 / xterm / part06 < prev    next >
Encoding:
Internet Message Format  |  1987-04-20  |  61.9 KB

  1. Subject:  v09i059:  Terminal emulator for X window system, Part06/07
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.TMC.COM
  4.  
  5. Submitted by: edmoy@opal.Berkeley.EDU
  6. Mod.sources: Volume 9, Issue 59
  7. Archive-name: xterm6.6b/Part06
  8.  
  9. #! /bin/sh
  10. # This is a shell archive, meaning:
  11. # 1. Remove everything above the #! /bin/sh line.
  12. # 2. Save the resulting text in a file.
  13. # 3. Execute the file with /bin/sh (not csh) to create the files:
  14. #    input.c menu.h misc.c resize.c screen.c
  15. if test -f input.c
  16. then
  17.     echo shar: will not overwrite existing file "'input.c'"
  18. else
  19. echo 'x - input.c'
  20. cat << \RAZZLE!DAZZLE > input.c
  21. /*
  22.  *    $Source: /u1/X/xterm/RCS/input.c,v $
  23.  *    $Header: input.c,v 10.100 86/12/01 14:44:04 jg Rel $
  24.  */
  25.  
  26. #ifndef lint
  27. static char *rcsid_input_c = "$Header: input.c,v 10.100 86/12/01 14:44:04 jg Rel $";
  28. #endif    lint
  29.  
  30. #include <X/mit-copyright.h>
  31.  
  32. /* Copyright    Massachusetts Institute of Technology    1984, 1985    */
  33.  
  34. /* input.c */
  35.  
  36. #ifndef lint
  37. static char sccs_id[] = "@(#)input.c\tX10/6.6B\t12/26/86";
  38. #endif    lint
  39.  
  40. #include <X/Xlib.h>
  41. #include <X/Xkeyboard.h>
  42. #include "scrollbar.h"
  43. #include "ptyx.h"
  44. #include <stdio.h>
  45.  
  46. static char *kypd_num = "0x.\r123456,789-";
  47. static char *kypd_apl = "pxnMqrstuvlwxym";
  48. static char *cur = "DCBA";
  49.  
  50. Input (keyboard, screen, event)
  51. register Keyboard    *keyboard;
  52. register Screen        *screen;
  53. register XKeyPressedEvent *event;
  54. {
  55.     register int keycode = event->detail;
  56.     register char *string;
  57.     register int col, key = FALSE;
  58.     int    pty    = screen->respond;
  59.     int    nbytes;
  60.     ANSI    reply;
  61.  
  62.     string = XLookupMapping (event, &nbytes);
  63.  
  64.     if (nbytes > 0) {
  65.         if(screen->TekGIN) {
  66.             TekEnqMouse(*string++);
  67.             TekGINoff();
  68.             nbytes--;
  69.         }
  70.         while (nbytes-- > 0)
  71.             unparseputc(*string++, pty);
  72.         key = TRUE;
  73.     } else {
  74.         keycode &= ValueMask; /* no longer need shift bits for anything */
  75.         reply.a_pintro = 0;
  76.         reply.a_final = 0;
  77.         reply.a_nparam = 0;
  78.         reply.a_inters = 0;
  79.         if (IsKeypadKey(keycode)) {
  80.           if (keyboard->flags & KYPD_APL)    {
  81.             reply.a_type   = SS3;
  82.             unparseseq(&reply, pty);
  83.             unparseputc(kypd_apl[keycode-KC_KEYPAD_0], pty);
  84.         } else
  85.             unparseputc(kypd_num[keycode-KC_KEYPAD_0], pty);
  86.         key = TRUE;
  87.         } else if (IsCursorKey(keycode)) {
  88.                if (keyboard->flags & CURSOR_APL) {
  89.             reply.a_type = SS3;
  90.             unparseseq(&reply, pty);
  91.             unparseputc(cur[keycode-KC_CURSOR_LEFT], pty);
  92.         } else {
  93.             reply.a_type = CSI;
  94.             reply.a_final = cur[keycode-KC_CURSOR_LEFT];
  95.             unparseseq(&reply, pty);
  96.         }
  97.         key = TRUE;
  98.         } else if (IsPFKey(keycode)) {
  99.         reply.a_type = SS3;
  100.         unparseseq(&reply, pty);
  101.         unparseputc((char)(keycode-KC_PF1+'P'), pty);
  102.         key = TRUE;
  103.         } else if (IsFunctionKey(keycode)) {
  104.         reply.a_type = CSI;
  105.         reply.a_nparam = 1;
  106.         reply.a_param[0] = funcvalue(keycode);
  107.         reply.a_final = '~';
  108.         if (reply.a_param[0] > 0)
  109.             unparseseq(&reply, pty);
  110.         key = TRUE;
  111.         }
  112.     }
  113.     if(key && !screen->TekEmu) {
  114.         if(screen->scrollkey && screen->topline != 0)
  115.             ScrollToBottom(screen->sb);
  116.         if(screen->marginbell) {
  117.             col = screen->max_col - screen->nmarginbell;
  118.             if(screen->bellarmed >= 0) {
  119.                 if(screen->bellarmed == screen->cur_row) {
  120.                     if(screen->cur_col >= col) {
  121.                         if(screen->cur_col == col)
  122.                             Bell();
  123.                         screen->bellarmed = -1;
  124.                     }
  125.                 } else
  126.                     screen->bellarmed = screen->cur_col <
  127.                      col ? screen->cur_row : -1;
  128.             } else if(screen->cur_col < col)
  129.                 screen->bellarmed = screen->cur_row;
  130.         }
  131.     }
  132. #ifdef ENABLE_PRINT
  133.     if (keycode == KC_F2) TekPrint();
  134. #endif
  135.     return;
  136. }
  137.  
  138. funcvalue(keycode)
  139. {
  140.     switch (keycode) {
  141.         case KC_F1:    return(11);
  142.         case KC_F2:    return(12);
  143.         case KC_F3:    return(13);
  144.         case KC_F4:    return(14);
  145.         case KC_F5:    return(15);
  146.         case KC_F6:    return(17);
  147.         case KC_F7:    return(18);
  148.         case KC_F8:    return(19);
  149.         case KC_F9:    return(20);
  150.         case KC_F10:    return(21);
  151.         case KC_F11:    return(23);
  152.         case KC_F12:    return(24);
  153.         case KC_F13:    return(25);
  154.         case KC_F14:    return(26);
  155.         case KC_F15:    return(28);
  156.         case KC_F16:    return(29);
  157.         case KC_F17:    return(31);
  158.         case KC_F18:    return(32);
  159.         case KC_F19:    return(33);
  160.         case KC_F20:    return(34);
  161.         case KC_E1 :    return(1);
  162.         case KC_E2:    return(2);
  163.         case KC_E3:    return(3);
  164.         case KC_E4:    return(4);
  165.         case KC_E5:    return(5);
  166.         case KC_E6:    return(6);
  167.         default:    return(-1);
  168.     }
  169. }
  170. RAZZLE!DAZZLE
  171. fi    # End input.c
  172. if test -f menu.h
  173. then
  174.     echo shar: will not overwrite existing file "'menu.h'"
  175. else
  176. echo 'x - menu.h'
  177. cat << \RAZZLE!DAZZLE > menu.h
  178. /*
  179.  *    $Source: /u1/X/xterm/RCS/menu.h,v $
  180.  *    $Header: menu.h,v 10.100 86/12/01 14:40:05 jg Rel $
  181.  */
  182.  
  183. /* @(#)menu.h       X10/6.6B 12/26/86 */
  184. /*
  185.  * Menu items are constructed as follows, starting from the left side:
  186.  *
  187.  *    menuItemPad
  188.  *    space for check mark
  189.  *    menuItemPad
  190.  *    text + padding
  191.  *    menuItemPad
  192.  *
  193.  * The padding for the text is that amount that this text is narrower than the
  194.  * widest text.
  195.  */
  196.  
  197. typedef struct _menuItem {
  198.     int itemHeight;            /* total height of this item */
  199.     int itemFlags;            /* flags of item */
  200.  
  201. #define    itemDisabled        0x0001    /* item is disabled */
  202. #define    itemChecked        0x0002    /* item has check mark */
  203. #define    itemStateMask        0x0003    /* mask for current state */
  204. #define    itemSetDisabled        0x0004    /* item wants to be disabled */
  205. #define    itemSetChecked        0x0008    /* item wants check mark */
  206. #define    itemSetMask        0x000c    /* mask for desired state */
  207. #define    itemSetMaskShift    2    /* for comparison with actual */
  208. #define    itemChanged        0x0010    /* item desires change */
  209.  
  210.     char *itemText;            /* text of item */
  211.     int itemTextWidth;        /* width of text */
  212.     int itemTextLength;        /* length of text */
  213.     struct _menuItem *nextItem;    /* next item in chain */
  214. } MenuItem;
  215.  
  216. typedef struct _menu {
  217.     int menuWidth;            /* full width of menu */
  218.     int menuHeight;            /* full height of menu */
  219.     int menuFlags;            /* flags of this menu */
  220.  
  221. # define    menuChanged    0x0001        /* menu changed, must redraw */
  222. # define    menuItemChanged    0x0002        /* item changed, must redraw */
  223. # define    menuMapped    0x0004        /* menu is now mapped */
  224. # define    menuFreeze    0x0008        /* freeze when doing menu */
  225. # define    menuSaveMenu    0x0010        /* save copy of menu */
  226.  
  227.     int menuMaxTextWidth;        /* width of widest text */
  228.     int menuInitialItem;        /* < 0 none, >= 0 initial item */
  229.     int menuBorderWidth;        /* width of border */
  230.     int menuBgColor;        /* background color */
  231.     int menuFgColor;        /* foreground color */
  232.     Pixmap menuBgTile;        /* backgroud tile */
  233.     FontInfo *menuFontInfo;        /* fontinfo for menu font */
  234.     int menuItemPad;        /* pad amount */
  235.     Window menuWindow;        /* window of menu */
  236.     int (*menuEventHandler)();    /* external event handler */
  237.     Cursor menuCursor;        /* cursor used in menu */
  238.     Pixmap menuSaved;        /* copy of menu */
  239.     Pixmap menuSavedImage;        /* copy of image under menu */
  240.     int menuSavedImageX;        /* X coordinate of the saved image */
  241.     int menuSavedImageY;        /* Y coordinate of the saved image */
  242.     MenuItem *menuItems;        /* head of menu item chain */
  243.     char *menuTitle;        /* title of menu */
  244.     int menuTitleWidth;        /* width of title */
  245.     int menuTitleLength;        /* length of title */
  246.     int menuItemTop;        /* position of top of first item */
  247. } Menu;
  248.  
  249. #define    checkMarkWidth        9
  250. #define    checkMarkHeight        8
  251. #define    defaultCursorWidth    16
  252. #define    defaultCursorHeight    16
  253. #define    defaultCursorX        1
  254. #define    defaultCursorY        1
  255. #define    grayHeight        16
  256. #define    grayWidth        16
  257. #define    lineSeparatorHeight    9
  258.  
  259. #define    CheckItem(menu,item)    SetItemCheck(menu,item,1)
  260. #define    DisableItem(menu,item)    SetItemDisable(menu,item,1)
  261. #define    EnableItem(menu,item)    SetItemDisable(menu,item,0)
  262. #define    SetMenuEventHandler(menu,f)    menu->menuEventHandler = f
  263. #define    UncheckItem(menu,item)    SetItemCheck(menu,item,0)
  264.  
  265. extern Menu *NewMenu();
  266. RAZZLE!DAZZLE
  267. fi    # End menu.h
  268. if test -f misc.c
  269. then
  270.     echo shar: will not overwrite existing file "'misc.c'"
  271. else
  272. echo 'x - misc.c'
  273. cat << \RAZZLE!DAZZLE > misc.c
  274. /*
  275.  *    $Source: /u1/X/xterm/RCS/misc.c,v $
  276.  *    $Header: misc.c,v 10.101 86/12/02 08:49:20 swick Exp $
  277.  */
  278.  
  279. #include <stdio.h>
  280. #include <setjmp.h>
  281. #include <signal.h>
  282. #include <ctype.h>
  283. #include <pwd.h>
  284. #include <sys/time.h>
  285. #include <sys/file.h>
  286. #include <X/Xlib.h>
  287. #include "scrollbar.h"
  288. #include "ptyx.h"
  289. #include "data.h"
  290. #include "error.h"
  291. #include "gray.ic"
  292. #include "hilite.ic"
  293. #include "icon.ic"
  294. #include "tek_icon.ic"
  295. #include "wait.ic"
  296. #include "waitmask.ic"
  297. #include "../cursors/left_ptr.cursor"
  298. #include "../cursors/left_ptr_mask.cursor"
  299. #include "../cursors/tcross.cursor"
  300. #include "../cursors/tcross_mask.cursor"
  301. #include "../cursors/xterm.cursor"
  302. #include "../cursors/xterm_mask.cursor"
  303.  
  304. #ifndef lint
  305. static char sccs_id[] = "@(#)misc.c\tX10/6.6B\t1/9/87";
  306. #endif    lint
  307.  
  308. xevents()
  309. {
  310.     XEvent reply;
  311.     register XEvent *rep = & reply;
  312.     register Screen *screen = &term.screen;
  313.  
  314.     if(screen->scroll_amt)
  315.         FlushScroll(screen);
  316.     XPending ();
  317.     do {
  318.         XNextEvent (&reply);
  319.         xeventpass(&reply);
  320.     } while (QLength() > 0);
  321. }
  322.  
  323. xeventpass(rep)
  324. register XEvent *rep;
  325. {
  326.     register Screen *screen = &term.screen;
  327.     register Window window = rep->window;
  328.     register Window w;
  329.     register int i;
  330.  
  331.     switch ((int)rep->type) {
  332.      case KeyPressed:
  333.         Input (&term.keyboard, &term.screen,
  334.          (XKeyPressedEvent *)rep);
  335.         break;
  336.  
  337.      case ExposeWindow:
  338.         if(screen->sb && window == screen->sb->bar) {
  339. #ifdef DEBUG
  340.             if(debug)
  341.                 fputs("ExposeWindow scrollbar\n", stderr);
  342. #endif DEBUG
  343.             if(((XExposeEvent *)rep)->subwindow ==
  344.              screen->sb->button) {
  345.                 screen->sb->buttonstate = -1;
  346.                 DrawButton(screen->sb);
  347.             } else if(((XExposeEvent *)rep)->subwindow ==
  348.              screen->sb->save) {
  349.                 screen->sb->savestate = -1;
  350.                 DrawSave(screen->sb);
  351.             }
  352.             break;
  353.         }
  354.         if (screen->active_icon) {
  355. #ifdef DEBUG
  356.             fputs( "ExposeWindow icon\n", stderr );
  357. #endif DEBUG
  358.             if (window == screen->iconVwin.window) {
  359.                 if (!screen->icon_show) {
  360.                 screen->mappedVwin = &screen->iconVwin;
  361.                 screen->icon_show = TRUE;
  362.                 screen->show = FALSE;
  363.                 screen->timer = 0;
  364.                 screen->holdoff = FALSE;
  365.                 if(screen->fullTwin.window)
  366.                 moveiconwindow( screen->fullTwin.window,
  367.                         screen->fullVwin.window );
  368.             }
  369.             if (screen->TekEmu)
  370.                 VTUnselect();
  371.             if (term.flags & ICONINPUT)
  372.                 reselectwindow(screen);
  373.             else
  374.                 unselectwindow(screen, INWINDOW);
  375.             screen->iconinput = FALSE;
  376.             VTExpose(rep);
  377.             } else if (window == screen->iconTwin.window) {
  378.             if (!screen->icon_show) {
  379.                 screen->mappedTwin = &screen->iconTwin;
  380.                 screen->icon_show = TRUE;
  381.                 screen->Tshow = FALSE;
  382.                 screen->timer = 0;
  383.                 screen->holdoff = FALSE;
  384.                 if (screen->fullVwin.window)
  385.                 moveiconwindow( screen->fullVwin.window,
  386.                         screen->fullTwin.window );
  387.             }
  388.             if (!screen->TekEmu)
  389.                 TekUnselect();
  390.             if (term.flags & ICONINPUT)
  391.                 reselectwindow(screen);
  392.             else
  393.                 unselectwindow(screen, INWINDOW);
  394.             screen->iconinput = FALSE;
  395.             TekExpose(rep);
  396.             }
  397.         } else if (window == screen->iconVwin.window ||
  398.                window == screen->iconTwin.window) {
  399. #ifdef DEBUG
  400.             if(debug)
  401.                 fprintf(stderr, "ExposeWindow %s\n", window ==
  402.                  screen->iconVwin.window ? "icon" : "Ticon");
  403. #endif DEBUG
  404.             RefreshIcon(screen, window);
  405.             break;
  406.         }
  407.         if(Titlebar(screen) || screen->icon_show) {
  408.         /* icon_show is a kludge as the titlebar exposure event
  409.          * frequently arrives before the full window exposure event */
  410.             if(window == screen->title.tbar) {
  411. #ifdef DEBUG
  412.             if(debug)
  413.                 fputs("ExposeWindow title\n", stderr);
  414. #endif DEBUG
  415.                 VTTitleExpose((XExposeWindowEvent *)rep);
  416.                 break;
  417.             } else if(window == screen->Ttitle.tbar) {
  418. #ifdef DEBUG
  419.             if(debug)
  420.                 fputs("ExposeWindow Ttitle\n", stderr);
  421. #endif DEBUG
  422.                 TekTitleExpose((XExposeWindowEvent *)rep);
  423.                 break;
  424.             }
  425.         }
  426.         if(window == screen->fullVwin.window) {
  427. #ifdef DEBUG
  428.             if(debug)
  429.                 fputs("ExposeWindow VT\n", stderr);
  430. #endif DEBUG
  431.             if(!screen->show) {
  432.                 screen->mappedVwin = &screen->fullVwin;
  433.                 if(screen->Ticonunmap) {
  434.                     screen->Ticonunmap = FALSE;
  435.                     XMapWindow( screen->fullTwin.window );
  436.                     screen->Tshow = TRUE;
  437.                     if(!screen->TekEmu) {
  438.                         screen->holdoff = TRUE;
  439.                         XUnmapTransparent(VWindow(screen));
  440.                         XMapWindow(VWindow(screen));
  441.                         break;
  442.                     }
  443.                 } else {
  444.                     screen->timer = 0;
  445.                     screen->holdoff = FALSE;
  446.                 }
  447.                 screen->show = TRUE;
  448.                 reselectwindow(screen);
  449.                 if(screen->icon_show && screen->deiconwarp)
  450.                     DeiconWarp(screen);
  451.  
  452.                 screen->icon_show = FALSE;
  453.                 screen->iconinput = FALSE;
  454.             }
  455.             VTExpose(rep);
  456.         } else if(window == screen->fullTwin.window) {
  457. #ifdef DEBUG
  458.             if(debug)
  459.                 fputs("ExposeWindow Tek\n", stderr);
  460. #endif DEBUG
  461.             if(!screen->Tshow) {
  462.                 screen->mappedTwin = &screen->fullTwin;
  463.                 if(screen->iconunmap) {
  464.                     screen->iconunmap = FALSE;
  465.                     XMapWindow( screen->fullVwin.window );
  466.                     screen->show = TRUE;
  467.                     if(screen->TekEmu) {
  468.                         screen->holdoff = TRUE;
  469.                         XUnmapTransparent(TWindow(screen));
  470.                         XMapWindow(TWindow(screen));
  471.                         break;
  472.                     }
  473.                 } else {
  474.                     screen->timer = 0;
  475.                     screen->holdoff = FALSE;
  476.                 }
  477.                 screen->Tshow = TRUE;
  478.                 reselectwindow(screen);
  479.                 if(screen->icon_show && screen->deiconwarp)
  480.                     DeiconWarp(screen);
  481.                 screen->icon_show = FALSE;
  482.                 screen->iconinput = FALSE;
  483.             }
  484.             TekExpose(rep);
  485.         }
  486.         break;
  487.  
  488.      case ExposeRegion:
  489.         if (!screen->active_icon && window == screen->iconVwin.window ||
  490.                window == screen->iconTwin.window) {
  491. #ifdef DEBUG
  492.             if(debug)
  493.                 fprintf(stderr, "ExposeRegion %s\n", window ==
  494.                  screen->iconVwin.window ? "icon" : "Ticon");
  495. #endif DEBUG
  496.             RefreshIcon(screen, window);
  497.             break;
  498.         }
  499. #ifdef DEBUG
  500.         if(debug)
  501.             fputs("ExposeRegion\n", stderr);
  502. #endif DEBUG
  503.         if (((XExposeWindowEvent *)rep)->detail == ExposeCopy &&
  504.             screen->incopy <= 0) {
  505.             screen->incopy = 1;
  506.             if (screen->scrolls > 0)
  507.                 screen->scrolls--;
  508.         }
  509.         if (HandleExposure (screen, rep))
  510.             screen->cursor_state = OFF;
  511.         break;
  512.  
  513.      case ExposeCopy:
  514. #ifdef DEBUG
  515.             if(debug)
  516.                 fputs("ExposeCopy\n", stderr);
  517. #endif DEBUG
  518.         if (screen->incopy <= 0 && screen->scrolls > 0)
  519.             screen->scrolls--;
  520.         if (screen->scrolls)
  521.             screen->incopy = -1;
  522.         else
  523.             screen->incopy = 0;
  524.         break;
  525.  
  526.      case ButtonPressed:
  527.         if (screen->incopy)
  528.             CopyWait (screen);
  529.         if(window == screen->iconVwin.window) {
  530. #ifdef DEBUG
  531.             if(debug)
  532.                 fputs("ButtonPressed icon\n", stderr);
  533. #endif DEBUG
  534.             XUnmapWindow(window);
  535.             if(screen->Ticonunmap && !screen->TekEmu) {
  536.                 screen->Ticonunmap = FALSE;
  537.                 XMapWindow(TWindow(screen));
  538.                 screen->Tshow = TRUE;
  539.                 screen->holdoff = TRUE;
  540.             }
  541.             XMapWindow(screen->fullVwin.window);
  542.             break;
  543.         } else if(window == screen->iconTwin.window) {
  544. #ifdef DEBUG
  545.             if(debug)
  546.                 fputs("ButtonPressed Ticon\n", stderr);
  547. #endif DEBUG
  548.             XUnmapWindow(window);
  549.             if(screen->iconunmap && screen->TekEmu) {
  550.                 screen->iconunmap = FALSE;
  551.                 XMapWindow(VWindow(screen));
  552.                 screen->show = TRUE;
  553.                 screen->holdoff = TRUE;
  554.             }
  555.             XMapWindow(screen->fullTwin.window);
  556.             break;
  557.         }
  558.         /* drop through */
  559.      case ButtonReleased:
  560. #ifdef DEBUG
  561.             if(debug)
  562.                 fputs("ButtonPressed or ButtonReleased\n",
  563.                  stderr);
  564. #endif DEBUG
  565.         HandleButtons(&term, rep, screen->respond);
  566.         break;
  567.  
  568.      case UnmapWindow:        /* full windows */
  569.         if (window == screen->fullVwin.window) {
  570. #ifdef DEBUG
  571.             if(debug)
  572.                 fputs("UnmapWindow VT\n", stderr);
  573. #endif DEBUG
  574.             if (screen->fullVwin.titlebar)
  575.                 VTTitleUnhilite();
  576.             screen->show = FALSE;
  577.             if(screen->Tshow) {
  578.                 screen->Ticonunmap = TRUE;
  579.                 screen->Tshow = FALSE;
  580.                 XUnmapWindow( screen->fullTwin.window );
  581.                 SyncUnmap( screen->fullTwin.window,
  582.                        TWINDOWEVENTS );
  583.             }
  584.         } else if(window == screen->fullTwin.window) {
  585. #ifdef DEBUG
  586.             if(debug)
  587.                 fputs("UnmapWindow Tek\n", stderr);
  588. #endif DEBUG
  589.             if (screen->fullTwin.titlebar)
  590.                 TekTitleUnhilite();
  591.             screen->Tshow = FALSE;
  592.             if(screen->show) {
  593.                 screen->iconunmap = TRUE;
  594.                 screen->show = FALSE;
  595.                 XUnmapWindow( screen->fullVwin.window );
  596.                 SyncUnmap( screen->fullVwin.window,
  597.                        WINDOWEVENTS );
  598.             }
  599.         }
  600.         reselectwindow(screen);
  601.         screen->timer = 0;
  602.         break;
  603.      case EnterWindow:
  604.         if(screen->sb) {
  605.             if(window == screen->sb->button) {
  606.                 if((i = GetButtonState(screen->sb)) !=
  607.                  BUTTON_NORMAL)
  608.                     SetButtonState(screen->sb, i | HILITED);
  609.                 break;
  610.             } else if(window == screen->sb->bar)
  611.                 break;
  612.         }
  613.         if((window == VWindow(screen) || window == TWindow(screen)) &&
  614.          (((XEnterWindowEvent *)rep)->detail & 0xff) !=
  615.          IntoOrFromSubwindow) {
  616. #ifdef DEBUG
  617.             if(debug)
  618.                 fprintf(stderr, "EnterWindow %s\n", window ==
  619.                  VWindow(screen) ? "VT" : "Tek");
  620. #endif DEBUG
  621.             screen->autowindow = window;
  622.             DoEnterLeave(screen, EnterWindow);
  623.         }
  624.         break;
  625.      case LeaveWindow:
  626.         if(screen->sb) {
  627.             if(window == screen->sb->button) {
  628.                 if((i = GetButtonState(screen->sb)) !=
  629.                  BUTTON_NORMAL)
  630.                     SetButtonState(screen->sb, i& ~HILITED);
  631.                 break;
  632.             } else if(window == screen->sb->bar)
  633.                 break;
  634.         }
  635.         if((window == VWindow(screen) || window == TWindow(screen)) &&
  636.          (((XEnterWindowEvent *)rep)->detail & 0xff) !=
  637.          IntoOrFromSubwindow)
  638. #ifdef DEBUG
  639.         {
  640.             if(debug)
  641.                 fprintf(stderr, "LeaveWindow %s\n", window ==
  642.                  VWindow(screen) ? "VT" : "Tek");
  643. #endif DEBUG
  644.             DoEnterLeave(screen, LeaveWindow);
  645. #ifdef DEBUG
  646.         }
  647. #endif DEBUG
  648.         break;
  649.      case FocusChange:
  650.         if(((XFocusChangeEvent *)rep)->detail == EnterWindow)
  651.             selectwindow(screen, FOCUS);
  652.         else
  653.             unselectwindow(screen, FOCUS);
  654.         break;
  655.      default:
  656.         break;
  657.     }
  658. }
  659.  
  660. selectwindow(screen, flag)
  661. register Screen *screen;
  662. register int flag;
  663. {
  664.     if(screen->TekEmu) {
  665.         TekSelect();
  666.         if(!Ttoggled)
  667.             TCursorToggle(TOGGLE);
  668.         if(screen->cellsused) {
  669.             screen->colorcells[2].pixel =
  670.              screen->Tcursorcolor;
  671.             XStoreColor(&screen->colorcells[2]);
  672.         }
  673.         screen->select |= flag;
  674.         if(!Ttoggled)
  675.             TCursorToggle(TOGGLE);
  676.         return;
  677.     } else {
  678.         VTSelect();
  679.         if(screen->cursor_state &&
  680.            (screen->cursor_col != screen->cur_col ||
  681.             screen->cursor_row != screen->cur_row))
  682.             HideCursor();
  683.         screen->select |= flag;
  684.         if(screen->cursor_state)
  685.             ShowCursor();
  686.         return;
  687.     }
  688. }
  689.  
  690. unselectwindow(screen, flag)
  691. register Screen *screen;
  692. register int flag;
  693. {
  694.     register int i;
  695.  
  696.     screen->select &= ~flag;
  697.     if(!screen->select) {
  698.         if(screen->TekEmu) {
  699.             TekUnselect();
  700.             if(!Ttoggled)
  701.                 TCursorToggle(TOGGLE);
  702.             if(screen->cellsused) {
  703.                 i = (term.flags & REVERSE_VIDEO) == 0;
  704.                 screen->colorcells[i].pixel =
  705.                  screen->Tcursorcolor;
  706.                 XStoreColor(
  707.                  &screen->colorcells[i]);
  708.             }
  709.             if(!Ttoggled)
  710.                 TCursorToggle(TOGGLE);
  711.             return;
  712.         } else {
  713.             VTUnselect();
  714.             if(screen->cursor_state &&
  715.              (screen->cursor_col != screen->cur_col ||
  716.              screen->cursor_row != screen->cur_row))
  717.                 HideCursor();
  718.             if(screen->cursor_state)
  719.                 ShowCursor();
  720.             return;
  721.         }
  722.     }
  723. }
  724.  
  725. reselectwindow(screen)
  726. register Screen *screen;
  727. {
  728.     Window win;
  729.     int x, y;
  730.  
  731.     if(XQueryMouse(RootWindow, &x, &y, &win)) {
  732.         if(win && (win == VWindow(screen) || win == TWindow(screen))
  733.                && (!screen->icon_show
  734.                || (screen->active_icon && term.flags & ICONINPUT)))
  735.             selectwindow(screen, INWINDOW);
  736.         else    unselectwindow(screen, INWINDOW);
  737.     }
  738. }
  739.  
  740. DeiconWarp(screen)
  741. register Screen *screen;
  742. {
  743.     if(screen->TekEmu)
  744.         XWarpMouse(TWindow(screen), TFullWidth(screen) / 2,
  745.          TFullHeight(screen) / 2);
  746.     else
  747.         XWarpMouse(VWindow(screen), FullWidth(screen) / 2,
  748.          FullHeight(screen) / 2);
  749. }
  750.  
  751. #define    ENTERLEAVE    500000L
  752.  
  753. DoEnterLeave(screen, type)
  754. register Screen *screen;
  755. int type;
  756. {
  757.     if (!screen->autoraise && !screen->holdoff) {
  758.         if (type == EnterWindow)
  759.             selectwindow( screen, INWINDOW );
  760.         else    unselectwindow( screen, INWINDOW );
  761.         return;
  762.     }
  763.  
  764.     screen->timer = type;
  765.     if(!screen->holdoff)
  766.         Timer(ENTERLEAVE);
  767. }
  768.  
  769. Timer(val)
  770. long val;
  771. {
  772.     struct itimerval it;
  773.  
  774.     bzero(&it, sizeof(it));
  775.     it.it_value.tv_usec = val;
  776.     setitimer(ITIMER_REAL, &it, (struct itimerval *)0);
  777. }
  778.  
  779. onalarm()
  780. {
  781.     register Screen *screen = &term.screen;
  782.  
  783.     if(screen->timer == 0 || screen->holdoff) {    /* extraneous alarm */
  784.         Timer(0L);
  785.         return;
  786.     }
  787.     if(screen->timer == EnterWindow) {
  788. #ifdef DEBUG
  789.         if(debug)
  790.             fprintf(stderr, "onalarm: EnterWindow %s\n",
  791.              screen->autoraise ? (screen->autowindow ==
  792.              VWindow(screen) ? "VT" : "Tek") : "");
  793. #endif DEBUG
  794.         selectwindow(screen, INWINDOW);
  795.         if(screen->autoraise)
  796.             XRaiseWindow(screen->autowindow);
  797.     } else    /* LeaveWindow */
  798. #ifdef DEBUG
  799.     {
  800.         if(debug)
  801.             fputs("onalarm: LeaveWindow\n", stderr);
  802. #endif DEBUG
  803.         unselectwindow(screen, INWINDOW);
  804. #ifdef DEBUG
  805.     }
  806. #endif DEBUG
  807.     screen->timer = 0;
  808. }
  809.  
  810. Pixmap make_hilite(fg, bg)
  811. int fg, bg;
  812. {
  813.     extern Pixmap Make_tile();
  814.  
  815.     return(Make_tile(hilite_width, hilite_height, hilite_bits, fg,
  816.      bg));
  817. }
  818.  
  819. Pixmap make_gray()
  820. {
  821.     extern Pixmap Make_tile();
  822.  
  823.     return(Make_tile(gray_width, gray_height, gray_bits, BlackPixel,
  824.      WhitePixel));
  825. }
  826.  
  827. Cursor make_tcross(fg, bg, func)
  828. int fg, bg, func;
  829. {
  830.     return(XCreateCursor(tcross_width, tcross_height, tcross_bits,
  831.      tcross_mask_bits, tcross_x_hot, tcross_y_hot, fg, bg, func));
  832. }
  833.  
  834. Cursor make_xterm(fg, bg, func)
  835. int fg, bg, func;
  836. {
  837.     return(XCreateCursor(xterm_width, xterm_height, xterm_bits,
  838.      xterm_mask_bits, xterm_x_hot, xterm_y_hot, fg, bg, func));
  839. }
  840.  
  841. Cursor make_wait(fg, bg, func)
  842. int fg, bg, func;
  843. {
  844.     return(XCreateCursor(wait_width, wait_height, wait_bits, waitmask_bits,
  845.      wait_x_hot, wait_y_hot, fg, bg, func));
  846. }
  847.  
  848. Cursor make_arrow(fg, bg, func)
  849. int fg, bg, func;
  850. {
  851.     return(XCreateCursor(left_ptr_width, left_ptr_height, left_ptr_bits,
  852.      left_ptr_mask_bits, left_ptr_x_hot, left_ptr_y_hot, fg, bg, func));
  853. }
  854.  
  855. char *uniquesuffix(name)
  856. char *name;
  857. {
  858.     register int *np, *fp, i;
  859.     register Window *cp;
  860.     register int temp, j, k, exact, *number;
  861.     char *wname;
  862.     Window *children, parent;
  863.     int nchildren;
  864.     static char *suffix, sufbuf[10];
  865.     char *malloc();
  866.  
  867.     if(suffix)
  868.         return(suffix);
  869.     suffix = sufbuf;
  870.     if(!XQueryTree(RootWindow, &parent, &nchildren, &children) ||
  871.      nchildren < 1 || (number = (int *)malloc(nchildren * sizeof(int)))
  872.      == NULL)
  873.         return(suffix);
  874.     exact = FALSE;
  875.     i = strlen(name);
  876.     for(np = number, cp = children, j = nchildren ; j > 0 ; cp++, j--) {
  877.         if(!XFetchName(*cp, &wname) || wname == NULL)
  878.             continue;
  879.         if(strncmp(name, wname, i) == 0) {
  880.             if(wname[i] == 0 || strcmp(&wname[i], " (Tek)") == 0)
  881.                 exact = TRUE;
  882.             else if(strncmp(&wname[i], " #", 2) == 0)
  883.                 *np++ = atoi(&wname[i + 2]);
  884.         }
  885.         free(wname);
  886.     }
  887.     free((char *)children);
  888.     if(exact) {
  889.         if(np <= number)
  890.             strcpy(suffix, " #2");
  891.         else {
  892.             exact = np - number;
  893.             np = number;
  894.             /* shell sort */
  895.             for(i = exact / 2 ; i > 0 ; i /= 2)
  896.                 for(k = i ; k < exact ; k++)
  897.                     for(j = k - i ; j >= 0 &&
  898.                      np[j] > np[j + i] ; j -= i) {
  899.                         temp = np[j];
  900.                         np[j] = np[j + i];
  901.                         np[j + i] = temp;
  902.                     }
  903.             /* make numbers unique */
  904.             for(fp = np + 1, i = exact - 1 ; i > 0 ; fp++, i--)
  905.                 if(*fp != *np)
  906.                     *++np = *fp;
  907.             /* find least unique number */
  908.             for(i = 2, fp = number ; fp <= np ; fp++) {
  909.                 if(i < *fp)
  910.                     break;
  911.                 if(i == *fp)
  912.                     i++;
  913.             }
  914.             sprintf(suffix, " #%d", i);
  915.         }
  916.     }
  917.     free((char *)number);
  918.     return(suffix);
  919. }
  920.  
  921. Bell()
  922. {
  923.     extern Terminal term;
  924.     register Screen *screen = &term.screen;
  925.  
  926.     if(screen->visualbell) {
  927.         if(screen->TekEmu) {
  928.             if(screen->icon_show && !screen->active_icon) {
  929.                 XPixSet(screen->iconTwin.window, 0, 0,
  930.                  screen->iconTwin.width, screen->iconTwin.height,
  931.                  screen->foreground);
  932.                 XFlush();
  933.                 XClear(screen->iconTwin.window);
  934.                 RefreshIcon(screen, screen->iconTwin.window);
  935.             } else {
  936.                 XPixFill(TWindow(screen), 0, 0,
  937.                  TFullWidth(screen), TFullHeight(screen),
  938.                  screen->foreground, (Bitmap)0, GXinvert,
  939.                  screen->xorplane);
  940.                 XFlush();
  941.                 XPixFill(TWindow(screen), 0, 0,
  942.                  TFullWidth(screen), TFullHeight(screen),
  943.                  screen->foreground, (Bitmap)0, GXinvert,
  944.                  screen->xorplane);
  945.             }
  946.         } else {
  947.             if(screen->icon_show && !screen->active_icon) {
  948.                 XPixSet(screen->iconVwin.window, 0, 0,
  949.                  screen->iconVwin.width, screen->iconVwin.height,
  950.                  screen->foreground);
  951.                 XFlush();
  952.                 XClear(screen->iconVwin.window);
  953.                 RefreshIcon(screen, screen->iconVwin.window);
  954.             } else {
  955.                 XPixSet(VWindow(screen), 0, 0, FullWidth(screen),
  956.                  FullHeight(screen), screen->foreground);
  957.                 XFlush();
  958.                 XClear(VWindow(screen));
  959.                 ScrnRefresh(screen, 0, 0, screen->max_row + 1 +
  960.                  screen->statusline, screen->max_col + 1);
  961.             }
  962.         }
  963.     } else
  964.         XFeep(0);
  965. }
  966.  
  967. Redraw()
  968. {
  969.     extern Terminal term;
  970.     register Screen *screen = &term.screen;
  971.  
  972.     if(VWindow(screen) && screen->show) {
  973.         VTExpose(NULL);
  974.         if(screen->scrollbar) {
  975.             XClear(screen->sb->bar);
  976.             XClear(screen->sb->region);
  977.             screen->sb->buttonstate = -1;
  978.             DrawButton(screen->sb);
  979.             screen->sb->savestate = -1;
  980.             DrawSave(screen->sb);
  981.         }
  982.         if(Titlebar(screen)) {
  983.             XClear(screen->title.tbar);
  984.             XClear(screen->title.left);
  985.             XClear(screen->title.right);
  986.             VTTitleExpose(NULL);
  987.         }
  988.     }
  989.     if(TWindow(screen) && screen->Tshow) {
  990.         TekExpose(NULL);
  991.         if(Titlebar(screen)) {
  992.             XClear(screen->Ttitle.tbar);
  993.             XClear(screen->Ttitle.left);
  994.             XClear(screen->Ttitle.right);
  995.             TekTitleExpose(NULL);
  996.         }
  997.     }
  998. }
  999.  
  1000. IconInit(screen, bm, Tbm)
  1001. register Screen *screen;
  1002. char *bm, *Tbm;
  1003. {
  1004.     register int w;
  1005.  
  1006.     if(!bm && !Tbm) {    /* use default bitmaps */
  1007.         screen->iconbitmap.bits = icon_bits;
  1008.         screen->Ticonbitmap.bits = tek_icon_bits;
  1009.         screen->bitmapwidth = screen->iconbitmap.width =
  1010.          screen->Ticonbitmap.width = icon_width;
  1011.         screen->bitmapheight = screen->iconbitmap.height =
  1012.          screen->Ticonbitmap.height = icon_height;
  1013.     } else if(bm && !*bm && Tbm && !*Tbm)    /* both empty means no bitmap */
  1014.         screen->bitmapwidth = screen->bitmapheight = 0;
  1015.     else {            /* user defined bitmap(s) */
  1016.         if(bm && *bm) {
  1017.             if((w = XReadBitmapFile(bm, &screen->iconbitmap.width,
  1018.              &screen->iconbitmap.height, &screen->iconbitmap.bits,
  1019.              NULL, NULL)) == 0) {
  1020. openerror:
  1021.                 fprintf(stderr, "%s: Can't open %s\n",
  1022.                  xterm_name, bm);
  1023.                 Exit(ERROR_OPENBITMAP);
  1024.             } else if(w < 0) {
  1025. syntaxerror:
  1026.                 fprintf(stderr, "%s: Syntax error in %s\n",
  1027.                  xterm_name, bm);
  1028.                 Exit(ERROR_SYNTAXBITMAP);
  1029.             }
  1030.             screen->bitmapwidth = screen->iconbitmap.width;
  1031.             screen->bitmapheight = screen->iconbitmap.height;
  1032.         }
  1033.         if(Tbm && *Tbm) {
  1034.             if((w = XReadBitmapFile(Tbm, &screen->Ticonbitmap.width,
  1035.              &screen->Ticonbitmap.height, &screen->Ticonbitmap.bits,
  1036.              NULL, NULL)) == 0)
  1037.                 goto openerror;
  1038.             else if(w < 0)
  1039.                 goto syntaxerror;
  1040.             if(screen->bitmapwidth < screen->Ticonbitmap.width)
  1041.                 screen->bitmapwidth = screen->Ticonbitmap.width;
  1042.             if(screen->bitmapheight < screen->Ticonbitmap.height)
  1043.                 screen->bitmapheight =
  1044.                  screen->Ticonbitmap.height;
  1045.         }
  1046.         if(!screen->iconbitmap.bits) {
  1047.             if(!screen->Ticonbitmap.bits) {
  1048.                 screen->Ticonbitmap.bits = tek_icon_bits;
  1049.                 screen->bitmapwidth = screen->Ticonbitmap.width
  1050.                  = icon_width;
  1051.                 screen->bitmapheight =
  1052.                  screen->Ticonbitmap.height = icon_height;
  1053.             }
  1054.             screen->iconbitmap.bits = screen->Ticonbitmap.bits;
  1055.             screen->iconbitmap.width = screen->Ticonbitmap.width;
  1056.             screen->iconbitmap.height = screen->Ticonbitmap.height;
  1057.         } else if(!screen->Ticonbitmap.bits) {
  1058.             if(!screen->iconbitmap.bits) {
  1059.                 screen->iconbitmap.bits = icon_bits;
  1060.                 screen->bitmapwidth = screen->iconbitmap.width
  1061.                  = icon_width;
  1062.                 screen->bitmapheight =
  1063.                  screen->iconbitmap.height = icon_height;
  1064.             }
  1065.             screen->Ticonbitmap.bits = screen->iconbitmap.bits;
  1066.             screen->Ticonbitmap.width = screen->iconbitmap.width;
  1067.             screen->Ticonbitmap.height = screen->iconbitmap.height;
  1068.         }
  1069.     }
  1070.     if((screen->winname = malloc(strlen(win_name) + 10)) == NULL)
  1071.         Error(ERROR_WINNAME);
  1072.     strcpy(screen->winname, win_name);
  1073.     strcat(screen->winname, uniquesuffix(win_name));
  1074.     screen->winnamelen = strlen(screen->winname);
  1075.     IconRecalc(screen);
  1076. }
  1077.  
  1078. IconRecalc(screen)
  1079. register Screen *screen;
  1080. {
  1081.     register int i, w;
  1082.  
  1083.     if (screen->active_icon) return;
  1084.  
  1085.     w = XQueryWidth(screen->winname, screen->titlefont->id);
  1086.     if(screen->bitmapwidth > 0) {
  1087.         if(screen->textundericon) {
  1088.             screen->icon_text_x = TITLEPAD;
  1089.             screen->icon_text_y = screen->bitmapheight +
  1090.              2 * TITLEPAD;
  1091.             screen->iconVwin.height = screen->bitmapheight +
  1092.               screen->titlefont->height + 3 * TITLEPAD;
  1093.             screen->iconbitmap.x = screen->Ticonbitmap.x =
  1094.              screen->iconbitmap.y = screen->Ticonbitmap.y =
  1095.              TITLEPAD;
  1096.             if((i = screen->bitmapwidth - w) >= 0) {
  1097.                 screen->iconVwin.width = screen->bitmapwidth +
  1098.                  2 * TITLEPAD;
  1099.                 screen->icon_text_x += i / 2;
  1100.             } else {
  1101.                 screen->iconVwin.width = w + 2 * TITLEPAD;
  1102.                 i = (-i) / 2;
  1103.                 screen->iconbitmap.x += i;
  1104.                 screen->Ticonbitmap.x += i;
  1105.             }
  1106.         } else {
  1107.             screen->icon_text_x = screen->bitmapwidth +
  1108.              2 * TITLEPAD;
  1109.             screen->icon_text_y = TITLEPAD;
  1110.             screen->iconVwin.width = w + screen->bitmapwidth +
  1111.              3 * TITLEPAD;
  1112.             screen->iconbitmap.x = screen->Ticonbitmap.x =
  1113.              screen->iconbitmap.y = screen->Ticonbitmap.y =
  1114.              TITLEPAD;
  1115.             if((i = screen->bitmapheight -
  1116.              screen->titlefont->height) >= 0) {
  1117.                 screen->iconVwin.height = screen->bitmapheight +
  1118.                  2 * TITLEPAD;
  1119.                 screen->icon_text_y += i / 2;
  1120.             } else {
  1121.                 screen->iconVwin.height = screen->titlefont->height
  1122.                  + 2 * TITLEPAD;
  1123.                 i = (-i) / 2;
  1124.                 screen->iconbitmap.y += i;
  1125.                 screen->Ticonbitmap.y += i;
  1126.             }
  1127.         }
  1128.         if((i = screen->iconbitmap.width - screen->Ticonbitmap.width)
  1129.          >= 0)
  1130.             screen->Ticonbitmap.x += i / 2;
  1131.         else
  1132.             screen->iconbitmap.x += (-i) / 2;
  1133.         if((i = screen->iconbitmap.height - screen->Ticonbitmap.height)
  1134.          >= 0)
  1135.             screen->Ticonbitmap.y += i / 2;
  1136.         else
  1137.             screen->iconbitmap.y += (-i) / 2;
  1138.     } else {
  1139.         screen->icon_text_x = TITLEPAD;
  1140.         screen->iconVwin.width = w + 2 * TITLEPAD;
  1141.         screen->iconVwin.height = screen->titlefont->height + 2 * TITLEPAD;
  1142.     }
  1143.  
  1144.     if (screen->iconVwin.window)
  1145.         XChangeWindow( screen->iconVwin.window, screen->iconVwin.width,
  1146.                screen->iconVwin.height );
  1147.  
  1148.     if (screen->iconTwin.window) {
  1149.         screen->iconTwin.width = screen->iconVwin.width;
  1150.         screen->iconTwin.height = screen->iconVwin.height;
  1151.         XChangeWindow( screen->iconTwin.window, screen->iconTwin.width,
  1152.                screen->iconTwin.height );
  1153.     }
  1154.  
  1155.     icon_box[0].x = screen->icon_text_x - 2;
  1156.     icon_box[0].y = screen->icon_text_y - 2;
  1157.     icon_box[3].x = -(icon_box[1].x = w + 3);
  1158.     icon_box[4].y = -(icon_box[2].y = screen->titlefont->height + 3);
  1159. }
  1160.  
  1161. RefreshIcon(screen, window)
  1162. register Screen *screen;
  1163. Window window;
  1164. {
  1165.     register BitmapBits *bb;
  1166.     register int fg, bg;
  1167.  
  1168.     bb = screen->TekEmu ? &screen->Ticonbitmap : &screen->iconbitmap;
  1169.     fg = screen->foreground;
  1170.     bg = screen->background;
  1171.     if(screen->bitmapwidth > 0)
  1172.         XBitmapBitsPut(window, bb->x, bb->y, bb->width, bb->height,
  1173.          bb->bits, fg, bg, (Bitmap)0, GXcopy, AllPlanes);
  1174.     XText(window, screen->icon_text_x, screen->icon_text_y,
  1175.      screen->winname, screen->winnamelen, screen->titlefont->id, fg, bg);
  1176.     screen->icon_show = TRUE;
  1177.     if(screen->iconinput)
  1178.         IconBox(screen);
  1179. }
  1180.  
  1181. IconBox(screen)
  1182. register Screen *screen;
  1183. {
  1184.     if (screen->active_icon) return;
  1185.  
  1186.     XDraw(screen->TekEmu ? screen->iconTwin.window : screen->iconVwin.window,
  1187.      icon_box, NBOX, 1, 1, screen->foreground, GXcopy, AllPlanes);
  1188. }
  1189.  
  1190. /*
  1191.  * Move win1's icon window to where win2's icon window is.
  1192.  */
  1193. moveiconwindow(win1, win2)
  1194. register Window win1, win2;
  1195. {
  1196.     WindowInfo wininfo1, wininfo2;
  1197.  
  1198.     XQueryWindow(win1, &wininfo1);
  1199.     XQueryWindow(win2, &wininfo2);
  1200.     if(wininfo1.assoc_wind && wininfo2.assoc_wind) {
  1201.         XQueryWindow(wininfo2.assoc_wind, &wininfo2);
  1202.         XMoveWindow(wininfo1.assoc_wind, wininfo2.x, wininfo2.y);
  1203.     }
  1204. }
  1205.  
  1206. IconGeometry(screen, ix, iy)
  1207. register Screen *screen;
  1208. register int *ix, *iy;
  1209. {
  1210.     register int i;
  1211.     int w, h;
  1212.  
  1213.     if(icon_geom) {
  1214.         i = XParseGeometry(icon_geom, ix, iy, &w, &h);
  1215.         /*
  1216.          * XParseGeometry returns negative values in addition to
  1217.          * setting the bitmask.
  1218.          */
  1219.         if((i & XValue) && (i & XNegative))
  1220.             *ix = DisplayWidth() + *ix - screen->iconVwin.width - 2 *
  1221.              screen->borderwidth;
  1222.         if((i & YValue) && (i & YNegative))
  1223.             *iy = DisplayHeight() + *iy - screen->iconVwin.height - 2 *
  1224.              screen->borderwidth;
  1225.     }
  1226. }
  1227.  
  1228. InTitle(screen, window, x)
  1229. register Screen *screen;
  1230. Window window;
  1231. int x;
  1232. {
  1233.     register int i, j;
  1234.  
  1235.     if(window == screen->title.tbar) {
  1236.         i = (j = FullWidth(screen) / 2) - (screen->title.x -
  1237.          screen->title_n_size);
  1238.         j = x - j;
  1239.         if(j < 0)
  1240.             j = -j;
  1241.         if(j < i) {
  1242.             XUnmapWindow(VWindow(screen));
  1243.             XMapWindow(screen->iconVwin.window);
  1244.             return(TRUE);
  1245.         }
  1246.     } else {
  1247.         i = (j = TFullWidth(screen) / 2) - (screen->Ttitle.x -
  1248.          screen->title_n_size);
  1249.         j = x - j;
  1250.         if(j < 0)
  1251.             j = -j;
  1252.         if(j < i) {
  1253.             XUnmapWindow(TWindow(screen));
  1254.             XMapWindow(screen->iconTwin.window);
  1255.             return(TRUE);
  1256.         }
  1257.     }
  1258.     return(FALSE);
  1259. }
  1260.  
  1261. SyncUnmap(win, mask)
  1262. register Window win;
  1263. register int mask;
  1264. {
  1265.     XEvent ev;
  1266.     register XEvent *rep = &ev;
  1267.  
  1268.     do { /* ignore events through unmap */
  1269.         XWindowEvent(win, mask, rep);
  1270.     } while(rep->type != UnmapWindow);
  1271. }
  1272.  
  1273. StartLog(screen)
  1274. register Screen *screen;
  1275. {
  1276.     register char *cp;
  1277.     register int i;
  1278.     static char *log_default;
  1279.     char *malloc(), *rindex();
  1280.     extern logpipe();
  1281.  
  1282.     if(screen->logging || (screen->inhibit & I_LOG))
  1283.         return;
  1284.     if(screen->logfile == NULL || *screen->logfile == 0) {
  1285.         if(screen->logfile)
  1286.             free(screen->logfile);
  1287.         if(log_default == NULL)
  1288.             mktemp(log_default = log_def_name);
  1289.         if((screen->logfile = malloc(strlen(log_default) + 1)) == NULL)
  1290.             return;
  1291.         strcpy(screen->logfile, log_default);
  1292.     }
  1293.     if(*screen->logfile == '|') {    /* exec command */
  1294.         int p[2];
  1295.         static char *shell;
  1296.  
  1297.         if(pipe(p) < 0 || (i = fork()) < 0)
  1298.             return;
  1299.         if(i == 0) {    /* child */
  1300.             close(p[1]);
  1301.             dup2(p[0], 0);
  1302.             close(p[0]);
  1303.             dup2(fileno(stderr), 1);
  1304.             dup2(fileno(stderr), 2);
  1305.             close(fileno(stderr));
  1306.             fileno(stderr) = 2;
  1307.             close(screen->display->fd);
  1308.             close(screen->respond);
  1309.             if(!shell) {
  1310.                 register struct passwd *pw;
  1311.                 char *getenv(), *malloc();
  1312.                 struct passwd *getpwuid();
  1313.  
  1314.                 if(((cp = getenv("SHELL")) == NULL || *cp == 0)
  1315.                  && ((pw = getpwuid(screen->uid)) == NULL ||
  1316.                  *(cp = pw->pw_shell) == 0) ||
  1317.                  (shell = malloc(strlen(cp) + 1)) == NULL)
  1318.                     shell = "/bin/sh";
  1319.                 else
  1320.                     strcpy(shell, cp);
  1321.             }
  1322.             signal(SIGHUP, SIG_DFL);
  1323.             signal(SIGCHLD, SIG_DFL);
  1324.             setgid(screen->gid);
  1325.             setuid(screen->uid);
  1326.             execl(shell, shell, "-c", &screen->logfile[1], 0);
  1327.             fprintf(stderr, "%s: Can't exec `%s'\n", xterm_name,
  1328.              &screen->logfile[1]);
  1329.             exit(ERROR_LOGEXEC);
  1330.         }
  1331.         close(p[0]);
  1332.         screen->logfd = p[1];
  1333.         signal(SIGPIPE, logpipe);
  1334.     } else {
  1335.         if(access(screen->logfile, F_OK) == 0) {
  1336.             if(access(screen->logfile, W_OK) < 0)
  1337.                 return;
  1338.         } else if(cp = rindex(screen->logfile, '/')) {
  1339.             *cp = 0;
  1340.             i = access(screen->logfile, W_OK);
  1341.             *cp = '/';
  1342.             if(i < 0)
  1343.                 return;
  1344.         } else if(access(".", W_OK) < 0)
  1345.             return;
  1346.         if((screen->logfd = open(screen->logfile, O_WRONLY | O_APPEND |
  1347.          O_CREAT, 0644)) < 0)
  1348.             return;
  1349.         chown(screen->logfile, screen->uid, screen->gid);
  1350.  
  1351.     }
  1352.     screen->logstart = screen->TekEmu ? Tbptr : bptr;
  1353.     screen->logging = TRUE;
  1354. }
  1355.  
  1356. CloseLog(screen)
  1357. register Screen *screen;
  1358. {
  1359.     if(!screen->logging || (screen->inhibit & I_LOG))
  1360.         return;
  1361.     FlushLog(screen);
  1362.     close(screen->logfd);
  1363.     screen->logging = FALSE;
  1364. }
  1365.  
  1366. FlushLog(screen)
  1367. register Screen *screen;
  1368. {
  1369.     register char *cp;
  1370.     register int i;
  1371.  
  1372.     cp = screen->TekEmu ? Tbptr : bptr;
  1373.     if((i = cp - screen->logstart) > 0)
  1374.         write(screen->logfd, screen->logstart, i);
  1375.     screen->logstart = screen->TekEmu ? Tbuffer : buffer;
  1376. }
  1377.  
  1378. logpipe()
  1379. {
  1380.     register Screen *screen = &term.screen;
  1381.  
  1382.     if(screen->logging)
  1383.         CloseLog(screen);
  1384. }
  1385.  
  1386. do_osc(func)
  1387. int (*func)();
  1388. {
  1389.     register Screen *screen = &term.screen;
  1390.     register int mode, c;
  1391.     register char *cp;
  1392.     char buf[512];
  1393.     extern char *malloc();
  1394.  
  1395.     mode = 0;
  1396.     while(isdigit(c = (*func)()))
  1397.         mode = 10 * mode + (c - '0');
  1398.     cp = buf;
  1399.     while(isprint(c = (*func)()))
  1400.         *cp++ = c;
  1401.     *cp = 0;
  1402.     switch(mode) {
  1403.      case 0:    /* new title */
  1404.         Retitle(buf);
  1405.         break;
  1406.      case 46:    /* new log file */
  1407.         if((cp = malloc(strlen(buf) + 1)) == NULL)
  1408.             break;
  1409.         strcpy(cp, buf);
  1410.         if(screen->logfile)
  1411.             free(screen->logfile);
  1412.         screen->logfile = cp;
  1413.         break;
  1414.     }
  1415. }
  1416.  
  1417. Retitle(name)
  1418. register char *name;
  1419. {
  1420.     register Screen *screen = &term.screen;
  1421.     register int w, i, j;
  1422.     char icon[512];
  1423.  
  1424.     free(screen->winname);
  1425.     if((screen->winname = malloc((screen->winnamelen = strlen(name)) + 1))
  1426.      == NULL)
  1427.         Error(ERROR_RTMALLOC1);
  1428.     strcpy(screen->winname, name);
  1429.     strcpy(icon, name);
  1430.     strcat(icon, " (icon)");
  1431.     IconRecalc(screen);
  1432.     if(screen->fullVwin.window) {
  1433.         XStoreName(screen->fullVwin.window, name);
  1434.         XStoreName(screen->iconVwin.window, icon);
  1435.         XChangeWindow(screen->iconVwin.window, screen->iconVwin.width,
  1436.          screen->iconVwin.height);
  1437.         if(screen->title.tbar) {
  1438.             w = FullWidth(screen);
  1439.             screen->title.fullwidth = XQueryWidth(name,
  1440.              screen->titlefont->id);
  1441.             if((screen->title.width = i = screen->title.fullwidth)
  1442.              > (j = w - 2 * (MINHILITE + screen->title_n_size + 1)))
  1443.                 screen->title.width = (i = j) +
  1444.                  screen->title_n_size;
  1445.             j = w - i - 2 * (screen->title_n_size + 1);
  1446.             i = j / 2;
  1447.             j -= i;
  1448.             screen->title.x = i + 1 + screen->title_n_size;
  1449.             screen->title.y = TITLEPAD;
  1450.             XClear(screen->title.tbar);
  1451.             XChangeWindow(screen->title.left, i,
  1452.              screen->titlefont->height);
  1453.             XConfigureWindow(screen->title.right, w - j - 1,
  1454.              TITLEPAD, j, screen->titlefont->height);
  1455.             VTTitleExpose((XExposeWindowEvent *)NULL);
  1456.         }
  1457.     }
  1458.     if(screen->fullTwin.window) {
  1459.         free(screen->Twinname);
  1460.         if((screen->Twinname = malloc((screen->Twinnamelen =
  1461.          screen->winnamelen + 6) + 1)) == NULL)
  1462.             Error(ERROR_RTMALLOC2);
  1463.         strcpy(screen->Twinname, name);
  1464.         strcat(screen->Twinname, " (Tek)");
  1465.         XStoreName(screen->fullTwin.window, screen->Twinname);
  1466.         XStoreName(screen->iconTwin.window, icon);
  1467.         XChangeWindow(screen->iconTwin.window, screen->iconTwin.width,
  1468.          screen->iconTwin.height);
  1469.         if(screen->Ttitle.tbar) {
  1470.             w = TFullWidth(screen);
  1471.             screen->Ttitle.fullwidth = XQueryWidth(screen->Twinname,
  1472.              screen->titlefont->id);
  1473.             if((screen->Ttitle.width = i = screen->Ttitle.fullwidth)
  1474.              > (j = w - 2 * (MINHILITE + screen->title_n_size + 1)))
  1475.                 screen->Ttitle.width = (i = j) +
  1476.                  screen->title_n_size;
  1477.             j = w - i - 2 * (screen->title_n_size + 1);
  1478.             i = j / 2;
  1479.             j -= i;
  1480.             screen->Ttitle.x = i + 1 + screen->title_n_size;
  1481.             screen->Ttitle.y = TITLEPAD;
  1482.             XClear(screen->Ttitle.tbar);
  1483.             XChangeWindow(screen->Ttitle.left, i,
  1484.              screen->titlefont->height);
  1485.             XConfigureWindow(screen->Ttitle.right, w - j - 1,
  1486.              TITLEPAD, j, screen->titlefont->height);
  1487.             TekTitleExpose((XExposeWindowEvent *)NULL);
  1488.         }
  1489.     }
  1490. }
  1491.  
  1492. Panic(s, a)
  1493. char    *s;
  1494. int a;
  1495. {
  1496. #ifdef DEBUG
  1497.     if(debug) {
  1498.         fprintf(stderr, "%s: PANIC!    ", xterm_name);
  1499.         fprintf(stderr, s, a);
  1500.         fputs("\r\n", stderr);
  1501.         fflush(stderr);
  1502.     }
  1503. #endif DEBUG
  1504. }
  1505.  
  1506. SysError (i)
  1507. int i;
  1508. {
  1509.     fprintf (stderr, "%s: Error %d, errno %d:", xterm_name, i, errno);
  1510.     perror ("");
  1511.     Cleanup(i);
  1512. }
  1513.  
  1514. Error (i)
  1515. int i;
  1516. {
  1517.     fprintf (stderr, "%s: Error %d\n", xterm_name, i);
  1518.     Cleanup(i);
  1519. }
  1520.  
  1521. /*
  1522.  * cleanup by sending SIGHUP to client processes
  1523.  */
  1524. Cleanup (code)
  1525. int code;
  1526. {
  1527. #ifdef notdef
  1528.     extern Terminal term;
  1529.     register Screen *screen;
  1530.  
  1531.     screen = &term.screen;
  1532.     if (screen->pid > 1)
  1533.         killpg(getpgrp(screen->pid), SIGHUP);
  1534. #endif
  1535.     Exit (code);
  1536. }
  1537.  
  1538. /*
  1539.  * sets the value of var to be arg in the Unix 4.2 BSD environment env.
  1540.  * Var should end with '=' (bindings are of the form "var=value").
  1541.  * This procedure assumes the memory for the first level of environ
  1542.  * was allocated using calloc, with enough extra room at the end so not
  1543.  * to have to do a realloc().
  1544.  */
  1545. Setenv (var, value)
  1546. register char *var, *value;
  1547. {
  1548.     extern char **environ;
  1549.     register int index = 0;
  1550.     register int len = strlen(var);
  1551.  
  1552.     while (environ [index] != NULL) {
  1553.         if (strncmp (environ [index], var, len) == 0) {
  1554.         /* found it */
  1555.         environ[index] = (char *)malloc (len + strlen (value) + 1);
  1556.         strcpy (environ [index], var);
  1557.         strcat (environ [index], value);
  1558.         return;
  1559.         }
  1560.         index ++;
  1561.     }
  1562.  
  1563. #ifdef DEBUG
  1564.     if (debug) fputs ("expanding env\n", stderr);
  1565. #endif DEBUG
  1566.  
  1567.     environ [index] = (char *) malloc (len + strlen (value) + 1);
  1568.     strcpy (environ [index], var);
  1569.     strcat (environ [index], value);
  1570.     environ [++index] = NULL;
  1571. }
  1572.  
  1573. /*
  1574.  * returns a pointer to the first occurrence of s2 in s1,
  1575.  * or NULL if there are none.
  1576.  */
  1577. char *strindex (s1, s2)
  1578. register char    *s1, *s2;
  1579. {
  1580.     register char    *s3;
  1581.     char        *index();
  1582.  
  1583.     while ((s3=index(s1, *s2)) != NULL) {
  1584.         if (strncmp(s3, s2, strlen(s2)) == 0)
  1585.             return (s3);
  1586.         s1 = ++s3;
  1587.     }
  1588.     return (NULL);
  1589. }
  1590.  
  1591. xerror(d, ev)
  1592. Display *d;
  1593. register XErrorEvent *ev;
  1594. {
  1595.     fprintf(stderr, "%s: %s\n", xterm_name,
  1596.      XErrDescrip(ev->error_code));
  1597.     fprintf(stderr, "Request code %d, func %d, serial #%ld, window %ld\n",
  1598.      ev->request_code, ev->func, ev->serial, (long)ev->window);
  1599.     Exit(ERROR_XERROR);
  1600. }
  1601.  
  1602. xioerror(d)
  1603. Display *d;
  1604. {
  1605.     perror(xterm_name);
  1606.     Exit(ERROR_XIOERROR);
  1607. }
  1608. RAZZLE!DAZZLE
  1609. fi    # End misc.c
  1610. if test -f resize.c
  1611. then
  1612.     echo shar: will not overwrite existing file "'resize.c'"
  1613. else
  1614. echo 'x - resize.c'
  1615. cat << \RAZZLE!DAZZLE > resize.c
  1616. /*
  1617.  *    $Source: /u1/X/xterm/RCS/resize.c,v $
  1618.  *    $Header: resize.c,v 10.101 86/12/02 10:35:30 swick Exp $
  1619.  */
  1620.  
  1621. #ifndef lint
  1622. static char *rcsid_resize_c = "$Header: resize.c,v 10.101 86/12/02 10:35:30 swick Exp $";
  1623. #endif    lint
  1624.  
  1625. #include <X/mit-copyright.h>
  1626.  
  1627. /* Copyright    Massachusetts Institute of Technology    1984    */
  1628.  
  1629. /* resize.c */
  1630.  
  1631. #include <stdio.h>
  1632. #include <sgtty.h>
  1633. #include <strings.h>
  1634. #include <ctype.h>
  1635. #include <sys/ioctl.h>
  1636. #include <signal.h>
  1637. #include <sys/time.h>
  1638.  
  1639. #ifndef lint
  1640. static char sccs_id[] = "@(#)resize.c\tX10/6.6B\t12/26/86";
  1641. #endif
  1642.  
  1643. #define    EMULATIONS    2
  1644. #define    SUN        1
  1645. #define    TIMEOUT        10
  1646. #define    VT100        0
  1647.  
  1648. char *emuname[EMULATIONS] = {
  1649.     "VT100",
  1650.     "Sun",
  1651. };
  1652. char *myname;
  1653. int stdsh;
  1654. char *getsize[EMULATIONS] = {
  1655.     "\0337\033[r\033[999;999H\033[6n",
  1656.     "\033[18t",
  1657. };
  1658. #ifndef sun
  1659. #ifdef TIOCSWINSZ
  1660. char *getwsize[EMULATIONS] = {
  1661.     0,
  1662.     "\033[14t",
  1663. };
  1664. #endif TIOCSWINSZ
  1665. #endif sun
  1666. char *restore[EMULATIONS] = {
  1667.     "\0338",
  1668.     0,
  1669. };
  1670. char *setname = "";
  1671. char *setsize[EMULATIONS] = {
  1672.     0,
  1673.     "\033[8;%s;%st",
  1674. };
  1675. struct sgttyb sgorig;
  1676. char *size[EMULATIONS] = {
  1677.     "\033[%d;%dR",
  1678.     "\033[8;%d;%dt",
  1679. };
  1680. char sunname[] = "sunsize";
  1681. int tty;
  1682. FILE *ttyfp;
  1683. #ifndef sun
  1684. #ifdef TIOCSWINSZ
  1685. char *wsize[EMULATIONS] = {
  1686.     0,
  1687.     "\033[4;%hd;%hdt",
  1688. };
  1689. #endif TIOCSWINSZ
  1690. #endif sun
  1691.  
  1692. char *strindex (), *index (), *rindex();
  1693.  
  1694. main (argc, argv)
  1695. char **argv;
  1696. /*
  1697.    resets termcap string to reflect current screen size
  1698.  */
  1699. {
  1700.     register char *ptr, *env;
  1701.     register int emu = VT100;
  1702.     int rows, cols;
  1703.     struct sgttyb sg;
  1704.     char termcap [1024];
  1705.     char newtc [1024];
  1706.     char buf[BUFSIZ];
  1707. #ifdef sun
  1708. #ifdef TIOCSSIZE
  1709.     struct ttysize ts;
  1710. #endif TIOCSSIZE
  1711. #else sun
  1712. #ifdef TIOCSWINSZ
  1713.     struct winsize ws;
  1714. #endif TIOCSWINSZ
  1715. #endif sun
  1716.     char *getenv();
  1717.     int onintr();
  1718.  
  1719.     if(ptr = rindex(myname = argv[0], '/'))
  1720.         myname = ptr + 1;
  1721.     if(strcmp(myname, sunname) == 0)
  1722.         emu = SUN;
  1723.     for(argv++, argc-- ; argc > 0 && **argv == '-' ; argv++, argc--) {
  1724.         switch((*argv)[1]) {
  1725.          case 's':    /* Sun emulation */
  1726.             if(emu == SUN)
  1727.                 Usage();    /* Never returns */
  1728.             emu = SUN;
  1729.             break;
  1730.          case 'u':    /* Bourne (Unix) shell */
  1731.               stdsh++;
  1732.             break;
  1733.          default:
  1734.             Usage();    /* Never returns */
  1735.         }
  1736.     }
  1737.     if(argc == 2) {
  1738.         if(!setsize[emu]) {
  1739.             fprintf(stderr,
  1740.              "%s: Can't set window size under %s emulation\n",
  1741.              myname, emuname[emu]);
  1742.             exit(1);
  1743.         }
  1744.         if(!checkdigits(argv[0]) || !checkdigits(argv[1]))
  1745.             Usage();    /* Never returns */
  1746.     } else if(argc != 0)
  1747.         Usage();    /* Never returns */
  1748.     if((ttyfp = fopen("/dev/tty", "r+")) == NULL) {
  1749.         fprintf(stderr, "%s: Can't open /dev/tty\n", myname);
  1750.         exit(1);
  1751.     }
  1752.     tty = fileno(ttyfp);
  1753.     if((env = getenv("TERMCAP")) && *env)
  1754.         strcpy(termcap, env);
  1755.     else {
  1756.         if(!(env = getenv("TERM")) || !*env) {
  1757.             env = "xterm";
  1758.             if(stdsh)
  1759.                 setname = "TERM=xterm;\n";
  1760.             else    setname = "setenv TERM xterm;\n";
  1761.         }
  1762.         if(tgetent (termcap, env) <= 0) {
  1763.             fprintf(stderr, "%s: Can't get entry \"%s\"\n",
  1764.              myname, env);
  1765.             exit(1);
  1766.         }
  1767.     }
  1768.  
  1769.      ioctl (tty, TIOCGETP, &sgorig);
  1770.     sg = sgorig;
  1771.     sg.sg_flags |= RAW;
  1772.     sg.sg_flags &= ~ECHO;
  1773.     signal(SIGINT, onintr);
  1774.     signal(SIGQUIT, onintr);
  1775.     signal(SIGTERM, onintr);
  1776.     ioctl (tty, TIOCSETP, &sg);
  1777.  
  1778.     if (argc == 2) {
  1779.         sprintf (buf, setsize[emu], argv[0], argv[1]);
  1780.         write(tty, buf, strlen(buf));
  1781.     }
  1782.     write(tty, getsize[emu], strlen(getsize[emu]));
  1783.     readstring(ttyfp, buf, size[emu]);
  1784.     if(sscanf (buf, size[emu], &rows, &cols) != 2) {
  1785.         fprintf(stderr, "%s: Can't get rows and columns\r\n", myname);
  1786.         onintr();
  1787.     }
  1788.     if(restore[emu])
  1789.         write(tty, restore[emu], strlen(restore[emu]));
  1790. #ifdef sun
  1791. #ifdef TIOCGSIZE
  1792.     /* finally, set the tty's window size */
  1793.     if (ioctl (tty, TIOCGSIZE, &ts) != -1) {
  1794.         ts.ts_lines = rows;
  1795.         ts.ts_cols = cols;
  1796.         ioctl (tty, TIOCSSIZE, &ts);
  1797.     }
  1798. #endif TIOCGSIZE
  1799. #else sun
  1800. #ifdef TIOCGWINSZ
  1801.     /* finally, set the tty's window size */
  1802.     if(getwsize[emu]) {
  1803.         /* get the window size in pixels */
  1804.         write (tty, getwsize[emu], strlen (getwsize[emu]));
  1805.         readstring(ttyfp, buf, wsize[emu]);
  1806.         if(sscanf (buf, wsize[emu], &ws.ws_xpixel, &ws.ws_ypixel) != 2) {
  1807.         fprintf(stderr, "%s: Can't get window size\r\n", myname);
  1808.         onintr();
  1809.         }
  1810.         ws.ws_row = rows;
  1811.         ws.ws_col = cols;
  1812.         ioctl (tty, TIOCSWINSZ, &ws);
  1813.     } else if (ioctl (tty, TIOCGWINSZ, &ws) != -1) {
  1814.         /* we don't have any way of directly finding out
  1815.            the current height & width of the window in pixels.  We try
  1816.            our best by computing the font height and width from the "old"
  1817.            struct winsize values, and multiplying by these ratios...*/
  1818.         if (ws.ws_xpixel != 0)
  1819.             ws.ws_xpixel = cols * (ws.ws_xpixel / ws.ws_col);
  1820.         if (ws.ws_ypixel != 0)
  1821.             ws.ws_ypixel = rows * (ws.ws_ypixel / ws.ws_row);
  1822.         ws.ws_row = rows;
  1823.         ws.ws_col = cols;
  1824.         ioctl (tty, TIOCSWINSZ, &ws);
  1825.     }
  1826. #endif TIOCGWINSZ
  1827. #endif sun
  1828.  
  1829.     ioctl (tty, TIOCSETP, &sgorig);
  1830.     signal(SIGINT, SIG_DFL);
  1831.     signal(SIGQUIT, SIG_DFL);
  1832.     signal(SIGTERM, SIG_DFL);
  1833.  
  1834.     /* update termcap string */
  1835.     /* first do columns */
  1836.     if ((ptr = strindex (termcap, "co#")) == NULL) {
  1837.         fprintf(stderr, "%s: No `co#'\n", myname);
  1838.         exit (1);
  1839.     }
  1840.     strncpy (newtc, termcap, ptr - termcap + 3);
  1841.     sprintf (newtc + strlen (newtc), "%d", cols);
  1842.     ptr = index (ptr, ':');
  1843.     strcat (newtc, ptr);
  1844.  
  1845.     /* now do lines */
  1846.     if ((ptr = strindex (newtc, "li#")) == NULL) {
  1847.         fprintf(stderr, "%s: No `li#'\n", myname);
  1848.         exit (1);
  1849.     }
  1850.     strncpy (termcap, newtc, ptr - newtc + 3);
  1851.     sprintf (termcap + ((int) ptr - (int) newtc + 3), "%d", rows);
  1852.     ptr = index (ptr, ':');
  1853.     strcat (termcap, ptr);
  1854.  
  1855.     if(stdsh)
  1856.         printf ("%sTERMCAP='%s'\n",
  1857.          setname, termcap);
  1858.     else    printf ("set noglob;\n%ssetenv TERMCAP '%s';\nunset noglob;\n",
  1859.          setname, termcap);
  1860.     exit(0);
  1861. }
  1862.  
  1863. char *strindex (s1, s2)
  1864. /*
  1865.    returns a pointer to the first occurrence of s2 in s1, or NULL if there are
  1866.    none.
  1867.  */
  1868. register char *s1, *s2;
  1869. {
  1870.     register char *s3;
  1871.  
  1872.     while ((s3 = index (s1, *s2)) != NULL)
  1873.     {
  1874.         if (strncmp (s3, s2, strlen (s2)) == 0) return (s3);
  1875.         s1 = ++s3;
  1876.     }
  1877.     return (NULL);
  1878. }
  1879.  
  1880. checkdigits(str)
  1881. register char *str;
  1882. {
  1883.     while(*str) {
  1884.         if(!isdigit(*str))
  1885.             return(0);
  1886.         str++;
  1887.     }
  1888.     return(1);
  1889. }
  1890.  
  1891. readstring(fp, buf, str)
  1892. register FILE *fp;
  1893. register char *buf;
  1894. char *str;
  1895. {
  1896.     register int i, last;
  1897.     struct itimerval it;
  1898.     int timeout();
  1899.  
  1900.     signal(SIGALRM, timeout);
  1901.     bzero((char *)&it, sizeof(struct itimerval));
  1902.     it.it_value.tv_sec = TIMEOUT;
  1903.     setitimer(ITIMER_REAL, &it, (struct itimerval *)NULL);
  1904.     if((*buf++ = getc(fp)) != *str) {
  1905.         fprintf(stderr, "%s: unknown character, exiting.\r\n", myname);
  1906.         onintr();
  1907.     }
  1908.     last = str[i = strlen(str) - 1];
  1909.     while((*buf++ = getc(fp)) != last);
  1910.     bzero((char *)&it, sizeof(struct itimerval));
  1911.     setitimer(ITIMER_REAL, &it, (struct itimerval *)NULL);
  1912.     *buf = 0;
  1913. }
  1914.  
  1915. Usage()
  1916. {
  1917.     fprintf(stderr, strcmp(myname, sunname) == 0 ?
  1918.      "Usage: %s [rows cols]\n" :
  1919.      "Usage: %s [-u] [-s [rows cols]]\n", myname);
  1920.     exit(1);
  1921. }
  1922.  
  1923. timeout()
  1924. {
  1925.     fprintf(stderr, "%s: Time out occurred\r\n", myname);
  1926.     onintr();
  1927. }
  1928.  
  1929. onintr()
  1930. {
  1931.     ioctl (tty, TIOCSETP, &sgorig);
  1932.     exit(1);
  1933. }
  1934. RAZZLE!DAZZLE
  1935. fi    # End resize.c
  1936. if test -f screen.c
  1937. then
  1938.     echo shar: will not overwrite existing file "'screen.c'"
  1939. else
  1940. echo 'x - screen.c'
  1941. cat << \RAZZLE!DAZZLE > screen.c
  1942. /*
  1943.  *    $Source: /u1/X/xterm/RCS/screen.c,v $
  1944.  *    $Header: screen.c,v 10.100 86/12/01 14:45:17 jg Rel $
  1945.  */
  1946.  
  1947. #include <X/mit-copyright.h>
  1948.  
  1949. /* Copyright    Massachusetts Institute of Technology    1984, 1985    */
  1950.  
  1951. /* screen.c */
  1952.  
  1953. #ifndef lint
  1954. static char sccs_id[] = "@(#)screen.c\tX10/6.6B\t12/26/86";
  1955. #endif    lint
  1956.  
  1957. #include <X/Xlib.h>
  1958. #include <stdio.h>
  1959. #include <sys/ioctl.h>
  1960. #include <signal.h>
  1961. #include "scrollbar.h"
  1962. #include "ptyx.h"
  1963. #include "error.h"
  1964.  
  1965. extern char *calloc();
  1966. extern char *malloc();
  1967. extern char *realloc();
  1968.  
  1969. ScrnBuf Allocate (nrow, ncol)
  1970. /*
  1971.    allocates memory for a 2-dimensional array of chars and returns a pointer
  1972.    thereto
  1973.    each line is formed from a pair of char arrays.  The first (even) one is
  1974.    the actual character array and the second (odd) one is the attributes.
  1975.  */
  1976. register int nrow, ncol;
  1977. {
  1978.     register ScrnBuf base;
  1979.  
  1980.     if ((base = (ScrnBuf) calloc ((nrow *= 2), sizeof (char *))) == 0)
  1981.         SysError (ERROR_SCALLOC);
  1982.  
  1983.     for (nrow--; nrow >= 0; nrow--)
  1984.         if ((base [nrow] = calloc (ncol, sizeof(char))) == 0)
  1985.             SysError (ERROR_SCALLOC2);
  1986.  
  1987.     return (base);
  1988. }
  1989.  
  1990. ScreenWrite (screen, str, flags, length)
  1991. /*
  1992.    Writes str into buf at row row and column col.  Characters are set to match
  1993.    flags.
  1994.  */
  1995. Screen *screen;
  1996. char *str;
  1997. register unsigned flags;
  1998. register int length;        /* length of string */
  1999. {
  2000.     register char *att;
  2001.     register int avail  = screen->max_col - screen->cur_col + 1;
  2002.     register char *col;
  2003.  
  2004.     if (length > avail)
  2005.         length = avail;
  2006.     if (length <= 0)
  2007.         return;
  2008.  
  2009.     col = screen->buf[avail = 2 * screen->cur_row] + screen->cur_col;
  2010.     att = screen->buf[avail + 1] + screen->cur_col;
  2011.     flags &= ATTRIBUTES;
  2012.     bcopy(str, col, length);
  2013.     while(length-- > 0)
  2014.         *att++ = flags;
  2015. }
  2016.  
  2017. ScrnInsertLine (sb, last, where, n, size)
  2018. /*
  2019.    Inserts n blank lines at sb + where, treating last as a bottom margin.
  2020.    Size is the size of each entry in sb.
  2021.    Requires: 0 <= where < where + n <= last
  2022.             n <= MAX_ROWS
  2023.  */
  2024. register ScrnBuf sb;
  2025. int last;
  2026. register int where, n, size;
  2027. {
  2028.     register int i;
  2029.     char *save [2 * MAX_ROWS];
  2030.  
  2031.     /* save n lines at bottom */
  2032.     bcopy ((char *) &sb [2 * (last -= n - 1)], (char *) save,
  2033.         2 * sizeof (char *) * n);
  2034.     
  2035.     /* clear contents of old rows */
  2036.     for (i = 2 * n - 1; i >= 0; i--)
  2037.         bzero ((char *) save [i], size);
  2038.  
  2039.     /* move down lines */
  2040.     bcopy ((char *) &sb [2 * where], (char *) &sb [2 * (where + n)],
  2041.         2 * sizeof (char *) * (last - where));
  2042.  
  2043.     /* reuse storage for new lines at where */
  2044.     bcopy ((char *)save, (char *) &sb[2 * where], 2 * sizeof(char *) * n);
  2045. }
  2046.  
  2047.  
  2048. ScrnDeleteLine (sb, last, where, n, size)
  2049. /*
  2050.    Deletes n lines at sb + where, treating last as a bottom margin.
  2051.    Size is the size of each entry in sb.
  2052.    Requires 0 <= where < where + n < = last
  2053.            n <= MAX_ROWS
  2054.  */
  2055. register ScrnBuf sb;
  2056. register int n, last, size;
  2057. int where;
  2058. {
  2059.     register int i;
  2060.     char *save [2 * MAX_ROWS];
  2061.  
  2062.     /* save n lines at where */
  2063.     bcopy ((char *) &sb[2 * where], (char *)save, 2 * sizeof(char *) * n);
  2064.  
  2065.     /* clear contents of old rows */
  2066.     for (i = 2 * n - 1 ; i >= 0 ; i--)
  2067.         bzero ((char *) save [i], size);
  2068.  
  2069.     /* move up lines */
  2070.     bcopy ((char *) &sb[2 * (where + n)], (char *) &sb[2 * where],
  2071.         2 * sizeof (char *) * ((last -= n - 1) - where));
  2072.  
  2073.     /* reuse storage for new bottom lines */
  2074.     bcopy ((char *)save, (char *) &sb[2 * last],
  2075.         2 * sizeof(char *) * n);
  2076. }
  2077.  
  2078.  
  2079. ScrnInsertChar (sb, row, col, n, size)
  2080. /*
  2081.    Inserts n blanks in sb at row, col.  Size is the size of each row.
  2082.  */
  2083. ScrnBuf sb;
  2084. int row, size;
  2085. register int col, n;
  2086. {
  2087.     register int i, j;
  2088.     register char *ptr = sb [2 * row];
  2089.     register char *att = sb [2 * row + 1];
  2090.  
  2091.     for (i = size - 1; i >= col + n; i--) {
  2092.         ptr[i] = ptr[j = i - n];
  2093.         att[i] = att[j];
  2094.     }
  2095.  
  2096.     bzero (ptr + col, n);
  2097.     bzero (att + col, n);
  2098. }
  2099.  
  2100.  
  2101. ScrnDeleteChar (sb, row, col, n, size)
  2102. /*
  2103.    Deletes n characters in sb at row, col. Size is the size of each row.
  2104.  */
  2105. ScrnBuf sb;
  2106. register int row, size;
  2107. register int n, col;
  2108. {
  2109.     register char *ptr = sb[2 * row];
  2110.     register char *att = sb[2 * row + 1];
  2111.     register nbytes = (size - n - col);
  2112.  
  2113.     bcopy (ptr + col + n, ptr + col, nbytes);
  2114.     bcopy (att + col + n, att + col, nbytes);
  2115.     bzero (ptr + size - n, n);
  2116.     bzero (att + size - n, n);
  2117. }
  2118.  
  2119.  
  2120. ScrnRefresh (screen, toprow, leftcol, nrows, ncols)
  2121. /*
  2122.    Repaints the area enclosed by the parameters.
  2123.    Requires: (toprow, leftcol), (toprow + nrows, leftcol + ncols) are
  2124.             coordinates of characters in screen;
  2125.          nrows and ncols positive.
  2126.  */
  2127. register Screen *screen;
  2128. int toprow, leftcol, nrows, ncols;
  2129. {
  2130.     int y = toprow * FontHeight(screen) + screen->border + Titlebar(screen);
  2131.     register int row;
  2132.     register int topline = screen->topline;
  2133.     int maxrow = toprow + nrows - 1;
  2134.     int scrollamt = screen->scroll_amt;
  2135.     int max = screen->max_row;
  2136.     int dostatus = 0, left, width;
  2137.     
  2138.  
  2139.     if(screen->statusline && maxrow == screen->max_row + 1) {
  2140.         dostatus++;
  2141.         maxrow--;
  2142.     }
  2143.     if(screen->cursor_col >= leftcol && screen->cursor_col <=
  2144.      (leftcol + ncols - 1) && screen->cursor_row >= toprow + topline &&
  2145.      screen->cursor_row <= maxrow + topline)
  2146.         screen->cursor_state = OFF;
  2147.     for( ; ; ) {
  2148.     for (row = toprow; row <= maxrow; y += FontHeight(screen), row++)
  2149.     {
  2150.        register char *chars;
  2151.        register char *att;
  2152.        register int col = leftcol;
  2153.        int maxcol = leftcol + ncols - 1;
  2154.        int lastind;
  2155.        int flags;
  2156.        int gxfunction;
  2157.        Font fnt;
  2158.        int x, yb, pix, n;
  2159.  
  2160.        lastind = row - scrollamt;
  2161.        if (lastind < 0 || lastind > max)
  2162.            continue;
  2163.        chars = screen->buf [2 * (lastind + topline)];
  2164.        att = screen->buf [2 * (lastind + topline) + 1];
  2165.  
  2166.        while (col <= maxcol && (att[col] & ~BOLD) == 0 &&
  2167.         (chars[col] & ~040) == 0)
  2168.         col++;
  2169.  
  2170.        while (col <= maxcol && (att[maxcol] & ~BOLD) == 0 &&
  2171.         (chars[maxcol] & ~040) == 0)
  2172.         maxcol--;
  2173.  
  2174.        if (col > maxcol) continue;
  2175.  
  2176.        flags = att[col];
  2177.  
  2178.        fnt = ActiveIcon(screen)
  2179.          ? screen->fnt_icon
  2180.          : (flags & BOLD)
  2181.            ? screen->fnt_bold
  2182.            : screen->fnt_norm;
  2183.  
  2184.        x = col * FontWidth(screen) + screen->border;
  2185.        lastind = col;
  2186.  
  2187.        for (; col <= maxcol; col++) {
  2188.         if (att[col] != flags) {
  2189.            if (((flags & INVERSE) != 0) ^ (dostatus < 0 &&
  2190.             screen->reversestatus))
  2191.                XText (VWindow(screen), x, y, &chars[lastind],
  2192.                 n = col - lastind, fnt,
  2193.                    pix = screen->background, screen->foreground);
  2194.            else
  2195.              XText (VWindow(screen), x, y, &chars[lastind],
  2196.                 n = col - lastind, fnt,
  2197.                    pix = screen->foreground, screen->background);
  2198.            if((flags & BOLD) && screen->enbolden)
  2199.              XTextMask (VWindow(screen), x + 1, y, &chars[lastind],
  2200.                 n, fnt, pix);
  2201.            if(flags & UNDERLINE) {
  2202.             yb = y + FontHeight(screen) - 2;
  2203.             XLine(VWindow(screen), x, yb, x + n * FontWidth(screen),
  2204.              yb, 1, 1, pix, GXcopy, AllPlanes);
  2205.            }
  2206.  
  2207.            x += (col - lastind) * FontWidth(screen);
  2208.  
  2209.            lastind = col;
  2210.  
  2211.            flags = att[col];
  2212.  
  2213.            fnt = ActiveIcon(screen)
  2214.                 ? screen->fnt_icon
  2215.              : (flags & BOLD)
  2216.                ? screen->fnt_bold
  2217.                : screen->fnt_norm;
  2218.         }
  2219.  
  2220.         if(chars[col] == 0)
  2221.             chars[col] = ' ';
  2222.        }
  2223.  
  2224.        if (((flags & INVERSE) != 0) ^ (dostatus < 0 &&
  2225.         screen->reversestatus))
  2226.            XText (VWindow(screen), x, y, &chars[lastind],
  2227.          n = col - lastind, fnt, pix = screen->background,
  2228.          screen->foreground);
  2229.        else
  2230.            XText (VWindow(screen), x, y, &chars[lastind],
  2231.          n = col - lastind, fnt, pix = screen->foreground,
  2232.          screen->background);
  2233.        if((flags & BOLD) && screen->enbolden)
  2234.         XTextMask (VWindow(screen), x + 1, y, &chars[lastind],
  2235.             n, fnt, pix);
  2236.        if(flags & UNDERLINE) {
  2237.         yb = y + FontHeight(screen) - 2;
  2238.         XLine(VWindow(screen), x, yb, x + n * FontWidth(screen), yb, 1, 1,
  2239.          pix, GXcopy, AllPlanes);
  2240.        }
  2241.     }
  2242.     if(dostatus <= 0)
  2243.         break;
  2244.     dostatus = -1;
  2245.     topline = 0;
  2246.     scrollamt = 0;
  2247.     toprow = maxrow = max = screen->max_row + 1;
  2248.     left = leftcol * FontWidth(screen) + screen->border;
  2249.     width = ncols * FontWidth(screen);
  2250.     if(leftcol == 0) {
  2251.         left--;
  2252.         width++;
  2253.     }
  2254.     if(leftcol + ncols - 1 >= screen->max_col)
  2255.         width++;
  2256.     XPixSet(VWindow(screen), left, y, width, screen->statusheight,
  2257.      screen->reversestatus ? screen->foreground : screen->background);
  2258.     if(!screen->reversestatus)
  2259.         StatusBox(screen);
  2260.     y++;
  2261.     }
  2262. }
  2263.  
  2264. ClearBufRows (screen, first, last)
  2265. /*
  2266.    Sets the rows first though last of the buffer of screen to spaces.
  2267.    Requires first <= last; first, last are rows of screen->buf.
  2268.  */
  2269. register Screen *screen;
  2270. register int first, last;
  2271. {
  2272.     first *= 2;
  2273.     last = 2 * last + 1;
  2274.     while (first <= last)
  2275.         bzero (screen->buf [first++], (screen->max_col + 1));
  2276. }
  2277.  
  2278. ScreenResize (screen, width, height, flags)
  2279. /*
  2280.    Resizes screen:
  2281.    1. If new window would have fractional characters, sets window size so as to
  2282.       discard fractional characters and returns -1.
  2283.       Minimum screen size is 1 X 1.
  2284.       Note that this causes another ExposeWindow event.
  2285.    2. Enlarges screen->buf if necessary.  New space is appended to the bottom
  2286.       and to the right
  2287.    3. Reduces  screen->buf if necessary.  Old space is removed from the bottom
  2288.       and from the right
  2289.    4. Cursor is positioned as closely to its former position as possible
  2290.    5. Sets screen->max_row and screen->max_col to reflect new size
  2291.    6. Maintains the inner border.
  2292.    7. Clears origin mode and sets scrolling region to be entire screen.
  2293.    8. Returns 0
  2294.  */
  2295. register Screen *screen;
  2296. int width, height;
  2297. unsigned *flags;
  2298. {
  2299.     register int rows, cols;
  2300.     register int index;
  2301.     register int savelines;
  2302.     register ScrnBuf sb = screen->allbuf;
  2303.     register ScrnBuf ab = screen->altbuf;
  2304.     register int x;
  2305.     register int border = 2 * screen->border;
  2306.     register int extra, i, j, k;
  2307.     register char *sl0, *sl1;    /* keep status line */
  2308.     double scale_x, scale_y;
  2309. #ifdef sun
  2310. #ifdef TIOCSSIZE
  2311.     struct ttysize ts;
  2312. #endif TIOCSSIZE
  2313. #else sun
  2314. #ifdef TIOCSWINSZ
  2315.     struct winsize ws;
  2316. #endif TIOCSWINSZ
  2317. #endif sun
  2318.  
  2319.  
  2320.     if (ActiveIcon(screen)) return( 0 );    /* don't resize on icon exposure */
  2321.  
  2322.     extra = Titlebar(screen) + screen->statusheight;
  2323.     /* round so that it is unlikely the screen will change size on  */
  2324.     /* small mouse movements.                    */
  2325.     rows = (height + FontHeight(screen) / 2 - border - extra) /
  2326.      FontHeight(screen);
  2327.     cols = (width + FontWidth(screen) / 2 - border - screen->scrollbar) /
  2328.      FontWidth(screen);
  2329.     if (rows < 1) rows = 1;
  2330.     if (cols < 1) cols = 1;
  2331.  
  2332.     if ((width - border - screen->scrollbar) % FontWidth(screen)
  2333.      != 0 || (height - border - extra) % FontHeight(screen) != 0 ||
  2334.      rows < screen->minrows) {
  2335.         XChangeWindow (VWindow(screen),
  2336.          cols * FontWidth(screen) + border + screen->scrollbar,
  2337.          (rows < screen->minrows ? screen->minrows : rows) *
  2338.          FontHeight(screen) + border + extra);
  2339.         return (-1);
  2340.     }
  2341.  
  2342.     /* change buffers if the screen has changed size */
  2343.     if (screen->max_row != rows - 1 || screen->max_col != cols - 1) {
  2344.         if(screen->cursor_state)
  2345.             HideCursor();
  2346.         savelines = screen->sb ? screen->savelines : 0;
  2347.         j = screen->max_col + 1;
  2348.         i = cols - j;
  2349.         k = screen->max_row;
  2350.         if(rows < k)
  2351.             k = rows;
  2352.         if(ab) {
  2353.             /* resize current lines in alternate buf */
  2354.             for (index = x = 0; index <= k; x += 2, index++) {
  2355.                 if ((ab[x] = realloc(ab[x], cols)) == NULL)
  2356.                     SysError(ERROR_SREALLOC);
  2357.                 if((ab[x + 1] = realloc(ab[x + 1], cols)) ==
  2358.                  NULL)
  2359.                     SysError (ERROR_SREALLOC2);
  2360.                 if (cols > j) {
  2361.                     bzero (ab [x] + j, i);
  2362.                     bzero (ab [x + 1] + j, i);
  2363.                 }
  2364.             }
  2365.             /* discard excess bottom rows in alt buf */
  2366.             for (index = rows, x = 2 * k ; index <=
  2367.              screen->max_row; x += 2, index++) {
  2368.                free (ab [x]);
  2369.                free (ab [x + 1]);
  2370.             }
  2371.         }
  2372.         /* resize current lines */
  2373.         k += savelines + 1;    /* includes status line */
  2374.         for (index = x = 0; index <= k; x += 2, index++) {
  2375.             if ((sb[x] = realloc(sb[x], cols)) == NULL)
  2376.                 SysError(ERROR_SREALLOC3);
  2377.             if((sb[x + 1] = realloc(sb[x + 1], cols)) == NULL)
  2378.                 SysError (ERROR_SREALLOC4);
  2379.             if (cols > j) {
  2380.                 bzero (sb [x] + j, i);
  2381.                 bzero (sb [x + 1] + j, i);
  2382.             }
  2383.         }
  2384.         /* discard excess bottom rows, but not status line */
  2385.         for (index = rows, x = 2 * (k - 1); index <= screen->max_row;
  2386.          x += 2, index++) {
  2387.            free (sb [x]);
  2388.            free (sb [x + 1]);
  2389.         }
  2390.         if(ab) {
  2391.             if((ab = (ScrnBuf)realloc(ab, 2 * sizeof(char *) * rows))
  2392.              == NULL)
  2393.             SysError (ERROR_RESIZE);
  2394.             screen->altbuf = ab;
  2395.         }
  2396.         /* save status line */
  2397.         sl0 = sb[i = 2 * (savelines + screen->max_row + 1)];
  2398.         sl1 = sb[i + 1];
  2399.         k = 2 * (rows + savelines + 1);    /* includes status line */
  2400.         /* resize sb */
  2401.         if((sb = (ScrnBuf)realloc(sb, k * sizeof(char *))) == NULL)
  2402.             SysError (ERROR_RESIZE2);
  2403.         screen->allbuf = sb;
  2404.         screen->buf = &sb[2 * savelines];
  2405.     
  2406.         if(ab) {
  2407.             /* create additional bottom rows as required in alt */
  2408.             for (index = screen->max_row + 1, x = 2 * index ;
  2409.              index < rows; x += 2, index++) {
  2410.                if((ab[x] = calloc (cols, sizeof(char))) == NULL)
  2411.                 SysError(ERROR_RESIZROW);
  2412.                if((ab[x + 1] = calloc (cols, sizeof(char))) == NULL)
  2413.                 SysError(ERROR_RESIZROW2);
  2414.             }
  2415.         }
  2416.         /* create additional bottom rows as required */
  2417.         for (index = screen->max_row + 1, x = 2 * (index + savelines) ;
  2418.          index < rows; x += 2, index++) {
  2419.            if((sb[x] = calloc (cols, sizeof(char))) == NULL)
  2420.             SysError(ERROR_RESIZROW3);
  2421.            if((sb[x + 1] = calloc (cols, sizeof(char))) == NULL)
  2422.             SysError(ERROR_RESIZROW4);
  2423.         }
  2424.  
  2425.         /* reinstall status line */
  2426.         sb[x = 2 * (rows + savelines)] = sl0;
  2427.         sb[x + 1] = sl1;
  2428.     
  2429.         screen->max_row = rows - 1;
  2430.         screen->max_col = cols - 1;
  2431.     
  2432.         /* adjust scrolling region */
  2433.         screen->top_marg = 0;
  2434.         screen->bot_marg = screen->max_row;
  2435.         *flags &= ~ORIGIN;
  2436.     
  2437.         if (screen->instatus)
  2438.             screen->cur_row = screen->max_row + 1;
  2439.         else if (screen->cur_row > screen->max_row)
  2440.             screen->cur_row = screen->max_row;
  2441.         if (screen->cur_col > screen->max_col)
  2442.             screen->cur_col = screen->max_col;
  2443.     
  2444.         screen->fullVwin.height = height - border - extra;
  2445.         screen->fullVwin.width = width - border - screen->scrollbar;
  2446.  
  2447.         if (screen->active_icon)
  2448.             SetIconSize( screen );
  2449.  
  2450.     } else if(FullHeight(screen) == height && FullWidth(screen) == width)
  2451.          return(0);    /* nothing has changed at all */
  2452.  
  2453.     if(screen->sb)
  2454.         ResizeScrollBar(screen->sb, width - SCROLLBARWIDTH,
  2455.          Titlebar(screen) - 1, height - Titlebar(screen), rows);
  2456.     if(screen->title.tbar && FullWidth(screen) != width)
  2457.         VTTitleResize(width);
  2458.     
  2459.     screen->fullVwin.fullheight = height;
  2460.     screen->fullVwin.fullwidth = width;
  2461. #ifdef sun
  2462. #ifdef TIOCSSIZE
  2463.     /* Set tty's idea of window size */
  2464.     ts.ts_lines = rows;
  2465.     ts.ts_cols = cols;
  2466.     ioctl (screen->respond, TIOCSSIZE, &ts);
  2467. #ifdef SIGWINCH
  2468.     if(screen->pid > 1)
  2469.         killpg(getpgrp(screen->pid), SIGWINCH);
  2470. #endif SIGWINCH
  2471. #endif TIOCSSIZE
  2472. #else sun
  2473. #ifdef TIOCSWINSZ
  2474.     /* Set tty's idea of window size */
  2475.     ws.ws_row = rows;
  2476.     ws.ws_col = cols;
  2477.     ws.ws_xpixel = width;
  2478.     ws.ws_ypixel = height;
  2479.     ioctl (screen->respond, TIOCSWINSZ, &ws);
  2480. #ifdef SIGWINCH
  2481.     if(screen->pid > 1)
  2482.         killpg(getpgrp(screen->pid), SIGWINCH);
  2483. #endif SIGWINCH
  2484. #endif TIOCSWINSZ
  2485. #endif sun
  2486.     return (0);
  2487. }
  2488.  
  2489.  
  2490. SetIconSize( screen )
  2491.   Screen *screen;
  2492. {
  2493.     if (screen->active_icon) {
  2494.         screen->iconVwin.width = (screen->max_col + 1)
  2495.                      * screen->iconVwin.f_width
  2496.                          + screen->border * 2;
  2497.         screen->iconVwin.height = (screen->max_row + 1)
  2498.                       * screen->iconVwin.f_height
  2499.                           + screen->border * 2;
  2500.         XChangeWindow( screen->iconVwin.window,
  2501.                screen->iconVwin.width,
  2502.                screen->iconVwin.height );
  2503.     } else {
  2504.         IconRecalc( screen );
  2505.     }
  2506.  
  2507.     screen->iconVwin.fullwidth = screen->iconVwin.width;
  2508.     screen->iconVwin.fullheight = screen->iconVwin.height;
  2509. }
  2510. RAZZLE!DAZZLE
  2511. fi    # End screen.c
  2512. echo '***** End of' xterm 6.6B - Part 6 of 7 '*****'
  2513. exit
  2514.  
  2515.